Web3.py: Block identifier parameter in Contract.call

Created on 20 Nov 2017  路  8Comments  路  Source: ethereum/web3.py

  • Version: 3.16.2
  • Python: 3.5
  • OS: linux

What was wrong?

I'm trying to query a contract state 6 block ago. Unlike web3.js api in Contract.call I can't specify block identifier to run this call against.
What is a correct way of doing this in web3py?
Am I correct in my understanding that as a workaround I can temporarily set Eth.defaultBlock to desired number and I won't run into any internal web3py thread/green thread concurrency issues?

How can it be fixed?

I'm feature-requesting addition of block identifier parameter in Contract.call in accord with web3.js api.

Good For Bounty

Most helpful comment

Yes, this should be added (and should be relatively easy to implement)

All 8 comments

Yes, this should be added (and should be relatively easy to implement)

Interesting that this API is not defined in the web3js v1 docs yet: https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html#methods-mymethod-call

Should it be an extra parameter to call? It doesn't really fit inside the transaction dict, semantically.

contract.method(...).call({'from': ..., 'gasPrice': ..., 'gas': ...}, at_block=123456)

I'd say extra optional parameter.

Hey guys...would love to go ahead on this one now...couple things.
1) Should this just be done for the upcoming v4 call interface or should I also build it out for the v3 interface as well (shouldn't require much additional work)?
2) Do you think it's worthwhile to throw an error if block number is outside valid range (0, length of chain]?

  1. v4-only should be fine. only critical security fixes need to go to v3 now, per #336
  2. It's absolutely worth throwing validation errors. I would also expect it to accept 'latest' and 'earliest'.

Cool sounds good, I'll get to work!

hello锛孖 get the web3 of vision4.2.1锛宐ut i cannot call my contract method at a block number,such as "detail = info.functions.getInfo().call(block_identifier=3)",I always get the "latest" block's info.Could tell me what's the reason of my problem?

Hi @mtcz91 that looks right. There's not enough info to help you debug.

This issue was left open by mistake, it is only tracking the main feature being added. I'm closing it now.

Can you open a new issue with a minimal, complete, and verifiable example: https://stackoverflow.com/help/mcve ? Specifically, the contract source, the contract deployment, any transactions, and the call.

Was this page helpful?
0 / 5 - 0 ratings