Python – How to Call a Deployed Smart Contract on Kovan Using Web3.py

contract-invocationkovanpythonremixweb3.py

The smart contract was written and deployed on Kovan using Remix IDE and injected Metamask Kovan test network account. However, I'll need python to deal with large input of a function in the smart contract. How can I do this? I have tried to register an Infura account and use it to interact with the function, the python code runs smoothly, but I can't see any changes to the smart contract. So I'm wondering how I can realize this goal. Thanks in advance.

My code logic is as follows.

w3 = Web3(Web3.HTTPProvider('https://kovan.infura.io/v3/...(my address)'))
ctr = w3.eth.contract(address=address, abi=abi) # address and abi are both specified previously
ctr.functions.my_func(input).call()

Best Answer

Any smart contract call cannot change the Ethereum state.

You need to perform a transaction and pay the gas fee to make any state changes. There are no free state changes.

Use transact() instead of call(). You will also need to set up a local private key.

Related Topic