-
I'm doing a sequence of rpc calls ( edit: my ethers version is at |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
If you are connecting to a JSON-RPC node that cannot change its chain ID, you probably want to use the It is in general necessary because many JSON-RPC connections, such as MetaMask, allow the user to change the chain ID on a whim, by clicking a drop-down in the UI. This will cause complete chaos if the check for chain ID is not made. For example, if you call getTransactionNonce on Ropsten and then send a transaction on mainnet, the nonce will likely not match, resulting in ether a NONCE_EXPIRED error or a transaction that will never get mined. Likewise, if you are querying for events, and the block number drastically changes, you are then possibly querying historic events or distant future events, when you intended to query for current events. But this is why the |
Beta Was this translation helpful? Give feedback.
-
reading the code, adding middleware for caching solves this problem. This RPC method was added to caching middleware (web3/middleware/cache.py) -> ethereum/web3.py@3e8f07c import web3
from web3.middleware import simple_cache_middleware
web3.middleware_onion.inject(simple_cache_middleware, layer=0) |
Beta Was this translation helpful? Give feedback.
-
@ricmoo I noticed this provider no longer exists in v6? Can you confirm that this is the new equivalent?
|
Beta Was this translation helpful? Give feedback.
If you are connecting to a JSON-RPC node that cannot change its chain ID, you probably want to use the
StaticJsonRpcProvider
, which doesn't perform this check.It is in general necessary because many JSON-RPC connections, such as MetaMask, allow the user to change the chain ID on a whim, by clicking a drop-down in the UI.
This will cause complete chaos if the check for chain ID is not made. For example, if you call getTransactionNonce on Ropsten and then send a transaction on mainnet, the nonce will likely not match, resulting in ether a NONCE_EXPIRED error or a transaction that will never get mined. Likewise, if you are querying for events, and the block number drastically changes, you a…