Introduction
Ganache CLI can fork an Ethereum network and run a local simulated Ethereum node based on EthereumJS.
This can be especially useful if you want to interact with the complex decentralized finance (DeFi) contracts deployed on the Ethereum mainnet in a local simulated environment.
Step-by-step
Deploy an Ethereum mainnet node with Chainstack
Deploy the 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 Beta
You must install Ganache CLI Beta as it has the basic authentication fix to work with the Ethereum nodes that require basic authentication.
Run:
npm install -g ganache-cli@v6.10.1-beta.2
Fork the Ethereum mainnet through the Chainstack node at the latest block
Run:
ganache-cli --fork https://USERNAME:PASSWORD@RPC_ENDPOINT
where
- USERNAME — your Ethereum node access username.
- PASSWORD — your Ethereum node access password.
- RPC_ENDPOINT — your Ethereum node RPC endpoint.
Example:
ganache-cli --fork https://user-name:pass-word-pass-word-pass-word@nd-123-456-789.p2pify.com
A forked Ethereum mainnet node is now running locally and you can interact with it.
Fork the Ethereum mainnet through the Chainstack node at a specific block
Run:
ganache-cli --fork https://USERNAME:PASSWORD@RPC_ENDPOINT@BLOCK_NUMBER
where
- USERNAME — your Ethereum node access username.
- PASSWORD — your Ethereum node access password.
- RPC_ENDPOINT — your Ethereum node RPC endpoint.
- BLOCK_NUMBER — the block number at which you want to fork.
Example:
ganache-cli --fork https://user-name:pass-word-pass-word-pass-word@nd-123-456-789.p2pify.com@8116664
A forked Ethereum mainnet node is now running locally and you can interact with it.
See also:
Comments
0 comments
Please sign in to leave a comment.