question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow specify block to fork at for "mainnet-fork"

See original GitHub issue

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?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
gosuto-inzasherucommented, Aug 31, 2021

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

1reaction
0xalfalfacommented, Jun 27, 2021

Here’s my workaround:

  • You need an archive node to go back more than 128 blocks. You can get one with the with Alchemy free tier.
  • In brownie-config.yaml set the fork up like this (adapt accordingly if you have a local archive node):
  mainnet-fork:
    cmd_settings:
        fork: https://eth-mainnet.alchemyapi.io/v2/$ALCHEMY_KEY$FORK_BLOCK_NUMBER
  • In your .env file set ALCHEMY_KEY=<ALCHECHMY_KEY>
  • If you always want to go back to the same block, also set e.g. FORK_BLOCK_NUMBER=@12710000 in the .env file.
  • If you want to go to a specific block in a python script, e.g. a test case, set the FORK_BLOCK_NUMBER environment variable in the first line of your python code:
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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Forking other networks | Ethereum development ... - Hardhat
Hardhat Network will by default fork from a recent mainnet block. ... depends on forking we recommend forking from a specific block number....
Read more >
Does anyone know how to fork a chain at a particular block on ...
To fork a blockchain with brownie, you actually just need to create a network that uses a forked blockchain or uses a forking...
Read more >
Fork the actual mainnet from a specific block - Stack Overflow
You can run Ganache with the --fork option. Fork from another currently running Ethereum client at a given block. Input should be the...
Read more >
How to Fork Ethereum Mainnet - Alchemy Docs
Hardhat will allow you to fork Mainnet to a local blockchain so that we can test and ... To confirm that we have...
Read more >
How To Fork Ethereum Mainnet with Hardhat - QuickNode
Forking the chain at an older block of the blockchain is helpful if you want to ... Now that we have our Hardhat...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found