Skip to content

This project demonstrates forking an existing chain to a local instance of ganache-cli.

Notifications You must be signed in to change notification settings

kevinbluer/ganache-fork

Repository files navigation

Ganache Forking Demo 🍴

This project demonstrates forking an existing chain to a local instance of ganache-cli.

Setup

Assuming you're using yarn, you'll be able to install the dependencies as follows:

yarn

You'll then need to create a .env file in the root of the project and set the environment variables as follows (with RPC_URL and NETWORK_ID matching those of the network from which you wish to fork from):

RPC_URL=http://my-rpc-node
NETWORK_ID=123456

Deploying Contracts

If the example contracts (e.g. SimpleStorage) aren't already deployed to the source network (e.g. the one you'll be forking from) then you'll need to that first.

truffle migrate --network source

After this it will be worth setting a value to the storedData state variable in the contract, so you'll be able to see it and set it within the forked instance.

truffle console --network fork
let i = await SimpleStorage.deployed()
i.set(42)

Forking

Assuming the above steps worked correctly you're now ready to fork the original network 🎉

npm run fork

Then connect to this now locally running forked instance with the following.

truffle console --network fork

You'll note the value should be the same as to what you set it on the source network.

let i = await SimpleStorage.deployed()
i.get()

We can now update this value without ever touching the source network.

i.set(24)

Going Deeper

While the above is somewhat contrived, it highlights the potential of forking, particularly when it comes to testing against contracts on existing networks. A good example of this can be found here.

Questions

Any questions, just reach out to [email protected].

About

This project demonstrates forking an existing chain to a local instance of ganache-cli.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published