This article applies to:
- Ethereum
- Polygon
- BNB Smart Chain
- Avalanche
- Fantom
- Harmony
Introduction
Ganache CLI can fork an EVM network and run a local simulated EVM node based on EthereumJS.
This can be especially useful if you want to interact with the complex decentralized finance (DeFi) contracts deployed on the mainnet in a local simulated environment.
You need an archive node to fork a mainnet.
Step-by-step
Deploy an archive node with Chainstack
Deploy an archive node as described in Join a public network.
Get the RPC endpoint and access credentials of your deployed node as described in View node access and credentials.
Install Ganache CLI
Run:
npm install -g ganache-cli
Fork the mainnet through the Chainstack node at the latest block
Run:
ganache-cli --fork HTTPS_ENDPOINT
where HTTPS_ENDPOINT is your node HTTPS endpoint.
Example:
ganache-cli --fork https://nd-123-456-789.p2pify.com/3c6e0b8a9c15224a8228b9a98ca1531
A forked mainnet node is now running locally and you can interact with it.
Fork the mainnet through the Chainstack node at a specific block
Run:
ganache-cli --fork HTTPS_ENDPOINT@BLOCK_NUMBER
where
- HTTPS_ENDPOINT — your node HTTPS endpoint.
- BLOCK_NUMBER — the block number at which you want to fork.
Example:
ganache-cli --fork https://nd-123-456-789.p2pify.com/3c6e0b8a9c15224a8228b9a98ca1531@8116664
A forked mainnet node is now running locally and you can interact with it.
See also:
Comments
0 comments
Article is closed for comments.