← Back to the blog
Lesson 1: Rethinking Web3 · Part 6/6 — Configuring a Local Test Chain

X ArticleWeb3

Lesson 1: Rethinking Web3 · Part 6/6 — Configuring a Local Test Chain

Source: https://x.com/i/status/2110719095440294041

Topic: Configuring a local test chain (Local Test Chains). Overview: Foundry / Ganache / Anvil / 10 local accounts to start playing with

3. Configuring a local test chain

There are two tools for starting a test chain locally:

Ganache

Foundry

Ganache

This is the simplest, and it has a graphical interface. But it is already outdated, and it is no longer maintained.

For a beginner, though, it can still be used to start a local test chain quickly.

Download and install it from the official site: https://archive.trufflesuite.com/ganache/

After opening it, click Quickstart.

The interface:

It includes 10 accounts. Click the key on the right to get the public and private keys.

Foundry

Foundry is a very popular, modern framework for smart contract development and testing, and it includes a local test network feature.

Installation

Documentation: https://www.getfoundry.sh/introduction/installation

Run this command to install: curl -L https://foundry.paradigm.xyz | bash

source ~/.bashrc / source ~/.zshrc.

foundryup

Starting the test network

Just run anvil.

As with Ganache, we immediately get 10 accounts, their public and private keys, and other network information.

As with Ganache, we immediately get 10 accounts, their public and private keys, and other network information

As with Ganache, we immediately get 10 accounts, their public and private keys, and other network information

Connecting the local test network in MetaMask

Open the settings menu in the upper right of MetaMask, and open the Networks panel.

Open the settings menu in the upper right of MetaMask, and open the Networks panel

Then click Add a custom network.

Then click Add a custom network

Then click Add a custom network

Connecting Ganache

The only critical field is this RPC URL, which you can see in the Ganache interface.

The only critical field is this RPC URL, which you can see in the Ganache interface

The only critical field is this RPC URL, which you can see in the Ganache interface

The other fields are either a name you can fill in freely, or, if you enter a wrong value, MetaMask will prompt you with the correct one.

Connecting Anvil

Likewise, the only critical field is the RPC URL. The others can be filled in freely, or you will get a prompt if you enter them incorrectly.

Likewise, the only critical field is the RPC URL. The others can be filled in freely, or you will get a prompt if you enter them incorrectly

You can see the specific information after starting Anvil.

You can see the specific information after starting Anvil

This is how we connect to the local test network.

Try adding an account from the test network. Upper left in MetaMask,

Try adding an account from the test network. Upper left in MetaMask,

Try adding an account from the test network. Upper left in MetaMask,

Import an Account

Here we click Import an Account, then enter the private key.

You can get a test account’s private key from the Ganache interface, or when you start Anvil.

Import a wallet

Get the seed phrase from Ganache’s main screen.

Get the seed phrase from Ganache’s main screen

Get the seed phrase from the information Anvil prints when it starts.

Get the seed phrase from the information Anvil prints when it starts

Fill in the seed phrase.

8. The import succeeded, and we can see that we have 10,000 GO

GO is the name of the token on the test network; you can pick any name.

GO is the name of the token on the test network; you can pick any name

Click Add account and add another account.

The accounts you add are all generated from the seed phrase. The same seed phrase will generate the same accounts in order, that is, the accounts you see when you start Ganache or Anvil.

The accounts you add are all generated from the seed phrase. The same seed phrase will generate the same accounts in order

Try a transfer. You can try transferring in the interface yourself; the steps are the same as a signed MetaMask transfer.

After the transfer is complete, you can see the two accounts’ balances change in the MetaMask interface.

Using the cast command with Anvil

The Ganache interface will display it

Exercises

Start your own test chain, then transfer between test accounts.

Series navigation (part 6 of 6)

Lesson 1: Rethinking Web3 is split into 6 X Articles.

← Previous: 01e — Transfers and DApp login

📚 Full table of contents: see README.md

🔗 Original long article: see ../01-Web3 认知重启.md

This part covers: configuring a local test chain

Code snippets from the article

The following code comes from code blocks in the original X Article, arranged in the order they appeared.

james@james-pan:~$ cast balance 0xD48d8edb8D5328bcba2410ac577980D2E00C576F
9899999958000000000000
james@james-pan:~$ cast balance 0x59533D0Defb7dB6fEdFfF2B0e268b2057FCfA864
10100000000000000000000
james@james-pan:~$

This article was imported from an X Article. Original: https://x.com/i/status/2110719095440294041