🚀What does it mean to fork the Mainnet?
In software development, creating a fork of something simply means “to create a copy of something that already exists”.
So, when we fork the Ethereum mainnet locally we have a copy of the main ethereum blockchain running on our PC.
When we do this, we have the current state of the blockchain running locally on our system, including all contracts deployed on it, all accounts created, all transactions performed on it.
🤷♂️Why do we fork the mainnet locally?
Creating a fork could be for different purposes or due to different reasons, ranging from:
- For testing purposes; when working on DEFI projects or any project that requires you to interact with deployed contracts. The best way to do this is through creating a fork locally.
- Development environments like; Hardhat, Truffle give users the ability to impersonate any account on the Mainnet.
You may need to perform a transaction with an account that owns DAI tokens and your local development account doesn't have enough DAI to perform that test.
Impersonating an actual account with enough DAI tokens, gives you the ability to do this.
😃How do we fork the mainnet locally?
For a tool like hardhat, it comes down to a simple command pointing to a node that is connected to the Ethereum mainnet.
To learn more on forking the mainnet with Hardhat, you can check these links:
Austin Griffith Live Coding Session
Hardhat Doc on Forking
Heyy, Hope it was interesting😃
I’m Ebube, and I love to write about stuff I learn.
Helps the learning process, you know.