-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Call contract method with blockhash requires fetching block number #3646
Comments
Hey @F4ever, thanks for the issue. Unfortunately, |
Hey @fselmo, thanks for responding! In practice, I haven’t encountered a single node that doesn’t support requests by block hash. However, there can be limitations on the client side — for example, block hashes may only be cached for the most recent N blocks. I believe such edge cases should be handled at the application level. It's true that block hashes aren’t explicitly mentioned in the spec, but that doesn’t mean we shouldn’t support the described feature. This library doesn’t aim to implement the interface 1:1 — and that’s perfectly fine. It was designed to simplify interaction with web3, not just serve as a thin wrapper around RPC requests. For example, according to the documentation, Web3.py should accept a block number as a hex string for the
At the moment, to implement support for passing block hashes to contract calls, I have to write a fairly large chunk of workaround code, which would break with each Web3.py update. I propose not necessarily implement my exact approach, but at least provide a cleaner way to bypass the current limitation. |
Hmm, that's fair. I was not aware that blockhash was widely accepted for edit: Also, TIL, it is already part of the official spec (this was not the case before) so I think we can definitely just default to this in the next major version as well, since it would be breaking to introduce it now. |
What feature should we add?
Hi everyone!
For security reasons, we're calling contracts using block hashes and avoiding block numbers to ensure that we don't receive responses from a fork.
However, the contract method makes an additional request to the node to retrieve the block number with the block hash, increasing node load and making an unnecessary request. See here:
https://github.com/ethereum/web3.py/blob/main/web3/contract/contract.py#L287
Would it be possible to modify the
parse_block_identifier
function to avoid this additional request?https://github.com/ethereum/web3.py/blob/main/web3/_utils/contracts.py#L349
e.g.
Related to:
#2816
The text was updated successfully, but these errors were encountered: