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

2 Answers 2


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

Load the abi with json loads function :

import json
with open('Contract.abi') as json_file:
    myabi = json.load(json_file)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.