I have a contract on Ropsten, and when I do this is python, I get a result:

result = contract.functions.getLastUpdateTime(0).call()

So I know the ABI is there, the address, etc.

There's another function getCurrentPrice on that same contract, which only differs in that it is restricted to be readable only for those querying with a certain address (ie, require(msg.sender = '0x123...')). I can get this to work in Remix, and have the public and private key that satisfies this restriction, so the problem is not that this function is screwed up.

Clearly, I need to tell it my public and/or private key info. Where do I add that to my transaction?

with open(contract_abi0) as f:
    contract_abi = json.load(f)
    contract = w3.eth.contract(address = contract_address, abi = contract_abi['abi'])
UpdateTime = contract.functions.getLastUpdateTime(0).call() # works!
Price = contract.functions.getCurrentPrice(0).call() # does not work :(
  • 1
    You tagged this with web3js, but this looks like Python code.
    – user19510
    Commented Oct 14, 2019 at 18:29
  • 1
    A small advice: If it really is a read-only function, then don't bother imposing this restriction because with just a little effort, anyone can retrieve the information that this function returns (remember, everything on the blockchain is essentially visible). Commented Oct 14, 2019 at 20:21
  • definitely true in general, but there are cases where this is helpful, so I wish I could figure this out... Commented Oct 15, 2019 at 15:20

1 Answer 1


Web3.py's ContractFunction.call method accepts a dictionary of transaction parameters in the same way as ContractFunction.transact. For example, if you wish to call the method from web3.eth.accounts[0]:

Price = contract.functions.getCurrentPrice(0).call({'from': web3.eth.accounts[0]})

Related links:

  • works! Interestingly, it doesn't require the required eth address's private key, just the eth address, unlike when calling from another contract. I suppose this is because this call is outside the EVM. Commented Oct 21, 2019 at 18:56

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.