Implement an ethers provider that wraps `ethersStateManager`
When we introduced the new ethersStateManager, it allows for essentially forking mainnet (or any chain) and running transactions locally against the state of that chain. One can chain transactions together and see the effect of multiple transactions on the state of the chain without actually submitting a real transaction.
It would be nice to implement a new ethers provider interface that extends the JsonRPCProvider by wrapping it with the ethersStateManager and proxying getBalance/getCode/getStorageAt state related calls to the ethersStateManager so that developers can make simulated testing against forked chain state much easier since they will be able to just use ethers without directly having to interact with the stateManager or other lower level primitives in the @ethereumjs stack.
An approximate implementation will be:
- Add a new
ethersForkedStateProviderfile under thestateManagerpackage - Create a new class that will extend the
jsonRpcProviderinterface fromethers - Accepts a remote RPC provider URL as a parameter
- Has the
ethersStateManageras a private element of the class - Override the
getAccount/getCode/getStorageAtfunctions with new innards that call the equivalent methods on theethersStateManagerobject (which will in turn call out to the remote RPC provider if the state isn't found locally).
Took a stab at this following the model of the Ultralight provider.
Biggest question has to do with getAccount - and what the equivalent ethers call is.
Took a stab at this following the model of the Ultralight provider.
Biggest question has to do with
getAccount- and what the equivalentetherscall is.
There isn't a 1-1 equivalent there. You would use it inside of ethers.provider.getBalance if the main one I can think of.
I just realized my original issue description wasn't exactly correct be there is no getAccount in the rpc. It's really just getBalance. You might also have to implement a wrapper around getTransactionCount and then use stateManager.getAccount to retrieve the nonce and return that.
There isn't a 1-1 equivalent there. You would use it inside of
ethers.provider.getBalanceif the main one I can think of.
So i should include a wrapper for getBalance and others that look up accounts?
There isn't a 1-1 equivalent there. You would use it inside of
ethers.provider.getBalanceif the main one I can think of.So i should include a wrapper for getBalance and others that look up accounts?
I think getBalance and getTransactionCount are the two. Would need to look through the rest of the rpc endpoint list to see if there are any others.
@acolytec3 can you take a peek at #2442 and tell me if I'm doing what you had in mind?
In working on it I found a couple inconsistencies in EthersStateManager. Between what the comments said should happen, and what was happening in the methods.
Will do today