from web3 import Web3
import json
from web3.providers.rpc import HTTPProvider
contractAddress = '0xmasked'
web3 = Web3(HTTPProvider('https://mainnet.infura.io'))
with open('contract.abi', 'r') as abi_definition:
    abi = json.load(abi_definition)

fContract = web3.eth.contract(abi,contractAddress)

Has anyone encountered the following error? From what I see I'm calling two arguments not three.

TypeError: contract() takes from 1 to 2 positional arguments but 3 were given
  • could you print the variable abi and share the output ? – Chim Jan 15 '18 at 12:02
  • 1
    One more thing, suggest to connect to a testnet instead of mainnet in infura – Chim Jan 15 '18 at 12:03
  • Based on that message, it seems you are on web3.py version 4 (beta). Can you confirm the exact version? – carver Jan 15 '18 at 17:46

In web3.py v4 (which I'm guessing you're on, based on the error), only the address can be passed as a positional argument.

To resolve the issue, initialize the contract with the ABI passed as a keyword argument, like so:

fContract = web3.eth.contract(contractAddress, abi=abi)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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