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:
1
npm install ganache --global
Copied!

Run Ganache on archive mode

Create a fork of Ethereum Mainnet, running Ganache on full archive mode using the following command:
Command
Output
1
ganache --fork
Copied!
1
ganache v7.1.0 (@ganache/cli: 0.2.0, @ganache/core: 0.2.0)
2
Starting RPC server
3
4
Available Accounts
5
==================
6
(0) 0x05547E31Ad92D209C3a35Ee6731AEb2b889D24c3 (1000 ETH)
7
(1) 0x797F834A4A725f8bad4Cc41D2aEB4686f4E64DeF (1000 ETH)
8
(2) 0xe28106C1ED8E3Ba2E42dde9a96D069eD1346B618 (1000 ETH)
9
(3) 0x88ad2e8352553BBeD046D4747F72F8c249680f89 (1000 ETH)
10
(4) 0xb23bEDD0b1606A95E8D777f2E0dEe2a54d2C676E (1000 ETH)
11
(5) 0xFBebd5d78B093759fFa7bcdD52fcDb7E03C6953E (1000 ETH)
12
(6) 0x3156477D06D63955A29575Bb92670923Ed72AB75 (1000 ETH)
13
(7) 0x237aBF430114868ABfb7f746a9867F400C757a68 (1000 ETH)
14
(8) 0xCE7BEfccb5bE9Af2368764e47782B83cF35ad6f7 (1000 ETH)
15
(9) 0xcc7AF74C0bE8D1520BcdB1207108dFD8733Cfba8 (1000 ETH)
16
17
Private Keys
18
==================
19
(0) 0x678f5b9a576230bd4fcec38be02e90420564521290dc05a72b0d4bf408f111eb
20
(1) 0x9f44a135a0fcd0e6121870a0b8fa1557a873ec3e5c46a4f3103fbb55beb898c5
21
(2) 0xb67d94cbd58f81261169fe40fad92fb913f655f298bcaafb87eaed29007465d8
22
(3) 0x1baf75d888f06bd94b587bcec2286d9b4f9b4f0bbfe0cfb9d92123871667d2f3
23
(4) 0xaa40fa56e410d305f8dad09f28734ac4a2a1a9db86a3789f4cf52b179183a117
24
(5) 0x62f786df56230c832a21d19cce74896f406495bf62694a587515bce2222d0e40
25
(6) 0x361a2baa296cd9cc2216abee83e53dcf0d34f5d53dec746fc954f631d1438641
26
(7) 0xe6163a3c46ef44b23e9a6f76eabbd6a9d670bd351941a4c86ac27142b8849b6f
27
(8) 0xb4545113924fca5434f650f3d29b0bb406f443a5ef19ac6eff18665ee4b62774
28
(9) 0xdb920c1f8b243ef4243a7711d2227dceedaa0b66aa572efa67b3aeec5f421436
29
30
HD Wallet
31
==================
32
Mnemonic: finish action spare lunch sausage cousin royal dry middle cram grunt powder
33
Base HD Path: m/44'/60'/0'/0/{account_index}
34
35
Default Gas Price
36
==================
37
2000000000
38
39
BlockGas Limit
40
==================
41
30000000
42
43
Call Gas Limit
44
==================
45
50000000
46
47
Forked Chain
48
==================
49
Location: Ethereum Mainnet, via 丕Infura
50
Block: 14696494
51
Network ID: 1
52
Time: Sun May 01 2022 22:34:01 GMT-0700 (Pacific Daylight Time)
53
54
Chain Id
55
==================
56
1337
57
58
RPC Listening on 127.0.0.1:8545
Copied!
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
1
curl -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0", "id": 1, "method": "eth_getBalance", "params": ["0xe5Fb31A5CaEE6a96de393bdBF89FBe65fe125Bb3", "0x1"] }' http://localhost:8545
Copied!
1
{"id":1,"jsonrpc":"2.0","result":"0x3635c9adc5dea00000"}
Copied!

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, ropsten, kovan, rinkeby, goerli, and görli.
Syntax
Example
1
ganache --fork.network <network name>
Copied!
1
ganache --fork.network rinkeby
Copied!

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/{PROJECT-ID}, 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 project secret, specify wss://:{PROJECT-SECRET}@mainnet.infura.com/ws/v3/{PROJECT-ID}.
Syntax
Example
1
ganache --fork.url <URL>
Copied!
1
ganache --fork.url wss://mainnet.infura.io/ws/v3/6e46ee5c0df54fb48c0fb2a94502c42a
Copied!

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.