Links

Fork Ethereum with Ganache

Ganache is a local development blockchain that simulates the Ethereum network, allowing developers to build and test dapps before releasing them to production.
The Ganache integration with Infura gives you access to Ethereum archive data, allowing you to fork the Ethereum network and replay historical transactions.

Install Ganache

To install Ganache, run:
npm install ganache --global

Run Ganache on archive mode

Create a fork of Ethereum Mainnet, running Ganache on full archive mode using the following command:
Command
Output
ganache --fork
ganache v7.1.0 (@ganache/cli: 0.2.0, @ganache/core: 0.2.0)
Starting RPC server
Available Accounts
==================
(0) 0x05547E31Ad92D209C3a35Ee6731AEb2b889D24c3 (1000 ETH)
(1) 0x797F834A4A725f8bad4Cc41D2aEB4686f4E64DeF (1000 ETH)
(2) 0xe28106C1ED8E3Ba2E42dde9a96D069eD1346B618 (1000 ETH)
(3) 0x88ad2e8352553BBeD046D4747F72F8c249680f89 (1000 ETH)
(4) 0xb23bEDD0b1606A95E8D777f2E0dEe2a54d2C676E (1000 ETH)
(5) 0xFBebd5d78B093759fFa7bcdD52fcDb7E03C6953E (1000 ETH)
(6) 0x3156477D06D63955A29575Bb92670923Ed72AB75 (1000 ETH)
(7) 0x237aBF430114868ABfb7f746a9867F400C757a68 (1000 ETH)
(8) 0xCE7BEfccb5bE9Af2368764e47782B83cF35ad6f7 (1000 ETH)
(9) 0xcc7AF74C0bE8D1520BcdB1207108dFD8733Cfba8 (1000 ETH)
Private Keys
==================
(0) 0x678f5b9a576230bd4fcec38be02e90420564521290dc05a72b0d4bf408f111eb
(1) 0x9f44a135a0fcd0e6121870a0b8fa1557a873ec3e5c46a4f3103fbb55beb898c5
(2) 0xb67d94cbd58f81261169fe40fad92fb913f655f298bcaafb87eaed29007465d8
(3) 0x1baf75d888f06bd94b587bcec2286d9b4f9b4f0bbfe0cfb9d92123871667d2f3
(4) 0xaa40fa56e410d305f8dad09f28734ac4a2a1a9db86a3789f4cf52b179183a117
(5) 0x62f786df56230c832a21d19cce74896f406495bf62694a587515bce2222d0e40
(6) 0x361a2baa296cd9cc2216abee83e53dcf0d34f5d53dec746fc954f631d1438641
(7) 0xe6163a3c46ef44b23e9a6f76eabbd6a9d670bd351941a4c86ac27142b8849b6f
(8) 0xb4545113924fca5434f650f3d29b0bb406f443a5ef19ac6eff18665ee4b62774
(9) 0xdb920c1f8b243ef4243a7711d2227dceedaa0b66aa572efa67b3aeec5f421436
HD Wallet
==================
Mnemonic: finish action spare lunch sausage cousin royal dry middle cram grunt powder
Base HD Path: m/44'/60'/0'/0/{account_index}
Default Gas Price
==================
2000000000
BlockGas Limit
==================
30000000
Call Gas Limit
==================
50000000
Forked Chain
==================
Location: Ethereum Mainnet, via 丕Infura
Block: 14696494
Network ID: 1
Time: Sun May 01 2022 22:34:01 GMT-0700 (Pacific Daylight Time)
Chain Id
==================
1337
RPC Listening on 127.0.0.1:8545
You can now send requests to this fork in a new terminal window. For example, use eth_getBalance to fetch the balance of address 0xe5Fb31A5CaEE6a96de393bdBF89FBe65fe125Bb3 at block 1:
Request
Response
curl -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0", "id": 1, "method": "eth_getBalance", "params": ["0xe5Fb31A5CaEE6a96de393bdBF89FBe65fe125Bb3", "0x1"] }' http://localhost:8545
{"id":1,"jsonrpc":"2.0","result":"0x3635c9adc5dea00000"}

Specify a network to fork

By default, the --fork option creates a fork of Ethereum Mainnet. Alternatively, specify which network to fork using the --fork.network option. The options are mainnet, goerli, and görli.
Syntax
Example
ganache --fork.network <network name>
ganache --fork.network goerli

Specify a provider URL

By default, Ganache uses Infura as the blockchain provider. Alternatively, specify the provider URL using the --fork.url option.
Specify your Infura URL, for example wss://mainnet.infura.io/ws/v3/{API-KEY}, or the URL of an Ethereum client, for example http://localhost:1337. You can specify the block to fork from using the @ sign, for example http://localhost:[email protected].
You can specify Basic Authentication credentials in the URL, for example wss://user:[email protected]/. If you need to use an Infura API key secret, specify wss://:{API-KEY-SECRET}@mainnet.infura.com/ws/v3/{API-KEY}.
Syntax
Example
ganache --fork.url <URL>
ganache --fork.url wss://mainnet.infura.io/ws/v3/6e46ee5c0df54fb48c0fb2a94502c42a

Other command line options

Additionally, use the following command line options when forking Ethereum with Ganache:
  • --fork.blockNumber - Block number to fork from. The default is the latest block number.
  • --fork.preLatestConfirmations - Number of blocks before the provider's latest block to fork from, when the fork.blockNumber is set to latest (default). The default is 5.
  • --fork.requestsPerSecond - Restrict the number of requests per second sent to the fork. The default is 0, which means no limit is applied.
  • --fork.disableCache - Disables caching of all forking requests. The default is false.
  • --fork.deleteCache - Deletes the persistent cache before starting. The default is false.
  • --fork.username - Username to use for Basic Authentication.
  • --fork.password - Password to use for Basic Authentication.
  • --fork.jwt - Encoded JSON Web Token (JWT) to use for Bearer Authentication.
  • --fork.headers - Headers to send to the fork on each request. Headers set using this option override headers set by the following options:
    • --fork.userAgent - User-Agent header to send to the fork on each request. Sent as Api-User-Agent when used in the browser.
    • --fork.origin - Origin header to send to the fork on each request. Ignored in the browser.