Contract Deployment – How to Interact with Deployed Contract ABI Using Web3.py

contract-deploymentcontract-invocationpythonweb3.py

I'm trying to interact with a smart contract I deployed with truffle using web3py
I can't figure out how to load the abi string into the web3py eth.contract function

contract = w3.eth.contract(address=contract_address, abi=...)

How do I load my ABI [ ] interface into the above function

Best Answer

In the latest version of web3py, the abi field accepts either of two types:

  • a list of dictionaries, defining the ABI
  • a string, that is the json-encoded version of the ABI
Related Topic