Open yanncks opened 4 years ago
alternatively, it isn't clear from these docs how to revert state to a specific block https://eth-brownie.readthedocs.io/en/stable/core-chain.html?highlight=time%20travel#time-travel. is that possible?
Should be possible, as a setting or cli flag, yes. Since most users don't have an archive node and thus are limited to the most recent 128 blocks, I figured there wouldn't be much demand. But it's not that hard to expose.
For time travel it isn't as easy. Ganache lets you declare a height when you launch, but you can't adjust that value once it's already running. So you can only ever go back in time as far as the initial height that you forked at.
Oh I see. When using Infura, does that give you access to an archive node?
Unfortunately not.
Any update on exposing the fork block?
I found a temporary solution is to run mainnet forking with hardhat at a specific block number I'm interested in, then connect brownie to that hardhat localhost RPC. Very handy for looking at internal transfers.
Here's my workaround:
mainnet-fork:
cmd_settings:
fork: https://eth-mainnet.alchemyapi.io/v2/$ALCHEMY_KEY$FORK_BLOCK_NUMBER
ALCHEMY_KEY=<ALCHECHMY_KEY>
FORK_BLOCK_NUMBER=@12710000
in the .env file.import os
os.environ["FORK_BLOCK_NUMBER"] = "@127110000"
This will only work when starting your python script yourself or through your VSCode debugger or such. If you start with brownie run
or brownie test
, you have to set all env variables before starting brownie.
i like that work-around @0xalfalfa! i was thinking something similar but with some bash magic and run it through brownie run
.
a proper implementation doesn't seem far away though, after finding out that ganache-cli
already has the parameter --fork_block_number
: https://github.com/trufflesuite/ganache/blob/master/README.md#options.
appears to me it only needs to be supported by the cmd-settings
part of the app that passes args to ganache? eg brownie run --network mainnet-fork --fork_block_number 13131313
.
dont know if i am the one to tackle this, but if anyone could give pointers on where to look in the code in order to prep a pr that would be cool :-) initial thought is to start by adding the cli flag here: https://github.com/eth-brownie/brownie/blob/master/brownie/network/rpc/ganache.py
Ganache supports specifying the block to fork at:
-f or --fork: Fork from another currently running Ethereum client at a given block. Input should be the HTTP location and port of the other client, e.g. http://localhost:8545. You can optionally specify the block to fork from using an @ sign: http://localhost:8545@1599200.
Would it be possible to surface this as a config or CLI option in brownie?