Developing our own Blockchain network for testing solidity contracts using Brownie (Mainnet forking with Alchemy & Infura)
Mainnet is the term used to describe when a blockchain protocol is fully developed and deployed, meaning that cryptocurrency transactions are being broadcasted, verified, and recorded on a distributed ledger technology (blockchain).
In contrast to mainnet networks, the term testnet describes when a blockchain protocol or network is not yet up and running on its full capacity. A testnet is used by programmers and developers to test and troubleshoot all the aspects and features of a blockchain network before they are sure the system is secure and ready for the mainnet launch.
In other words, a testnet only exists as a working prototype for a blockchain project, while a mainnet is a completely developed blockchain platform for users to send and receive cryptocurrency transactions (or any other kind of digital data that is recorded on a distributed ledger)
~Obasi Ifegwu
Procedure:
- First, let's see existing networks in Brownie using the following command:
brownie networks list

2. I want to name my new network mainnet-fork
but wait, there is already one with the same name. mainnet-fork
is actually a built-in network in Brownie. So let’s delete it, because why not!
# to delete existing network
brownie networks delete mainnet-fork

Great! isn’t it? By the way, for surety purposes, you can rerun the above command to have a look at existing networks.
3. We can use Infura or Alchemy for forking.
* Alchemy:

- First, go to alchemy.com and log in or signup(in case you haven’t).

- Create a New App with the following settings.

- Open
forkingDemo
and click onview key
and copy the one under HTTP (first one)

- Execute the following command in VSCode terminal
( ctrl+` )
# following command
brownie networks add development mainnet-fork cmd=ganache-cli host=http://127.0.0.1 fork=[paste copied key here] accounts=10 mnemonic=brownie port=8545
- The output should be the following:

* Infura:
- First, go to infura.io and sign in.
- Open
Dashboard > Create New Project
Product > Ethereum
and Create

- Open your project, go to project settings. It will look something like this:

- Copy that
https link
under ENDPOINTS. - Execute the following command in VSCode terminal
( ctrl+` )
# following command
brownie networks add development mainnet-fork cmd=ganache-cli host=http://127.0.0.1 fork=[paste copied key here] accounts=10 mnemonic=brownie port=8545
3. Testing:
For testing with mainnet-fork
use:
brownie test --network mainnet-fork
& the END!
Congrats!!! You have done it. Happy testing xD