Local testnet
Local networks are a useful way to get started with Filecoin development. This guide covers how to start a local network using Lotus as the Filecoin node implementation.
Setup
A Filecoin network has two node types: storage provider nodes and client nodes. In our local developer network (devnet), we’re going to create a single storage provider node to handle our requests, and we’ll also create a client node to pass information into our network. Both of these nodes run in the terminal. In total, we’ll have three terminal windows open at once.
Prerequisites
The nodes we’re going to run have relatively lightweight hardware requirements. However, since we’re running multiple instances at once it’s recommended that your computer meets the following requirements:
At least 8 GiB of RAM
A quad-core CPU.
(Optional) Because parts of this tutorial require multiple terminal windows, install a terminal multiplexer like Tmux.
Steps
To build the nodes, you’ll need some specific software. Run the following command to install the software prerequisites:
Open a terminal window.
Install the following dependencies:\
brew install go bzr jq pkg-config hwloc coreutilsInstall Rust:\
curl https://sh.rustup.rs -sSf | sh -s -- -y # ... # Rust is installed now. Great! # ...Source the
~/.cargo/envconfig file:\source "$HOME/.cargo/env"
Install the following dependencies:\
Install Go and add
/usr/local/go/binto your$PATHvariable:\You may need to export
/usr/local/go/binto your$PATH. This process changes depending on which shell you’re using:
Bash
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc && source ~/.bashrc
ZSH
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.zshrc && source ~/.zshrc
Install Rust and source the
~/.cargo/envconfig file:
Done! You can move on to the Pre-build section.
Pre-build
Before we can build the Lotus binaries, there’s some setup we need to do. We’ll create the executable binaries within a new ~/lotus-devnet.
Clone the repository:\
Checkout to the latest stable branch:\
Done! You can move on to the Build section.
Clone the repository into a new
~/lotus-devnetdirectory:\Checkout to the latest stable branch:\
Create the necessary environment variables to allow Lotus to run on M1 architecture:\
Done! You can move on to the Build section.
Clone the repository into a new
~/lotus-devnetdirectory:\Checkout to the latest stable branch:\
If your processor was released later than an AMD Zen or Intel Ice Lake CPU, enable the use of SHA extensions by adding these two environment variables:\
If in doubt, ignore this command and move on to the next section.
Done! You can move on to the Build section.
Build
Create the
2kbinary for Lotus:\This will output something like:\
This process will take about 5 minutes to complete.
Fetch the proving parameters for a 2048-byte sector size:\
This will output something like:\
This process downloads a few files totalling to around 2 GiB in size. Depending on your internet speed, this process can take a few minutes to complete.
Pre-seal two sectors for the genesis block:\
This will output something like:\
Create the genesis block:\
Create a pre-miner and an address with some funds:\
This will output something like:\
Our Lotus installation is now ready to start running the nodes!
Start the nodes
As mentioned earlier, we will be running two types of a node: a storage provider node and a client node. In the Lotus project, a storage provider node is referred to as a miner. Since we’re going to run multiple nodes, you’ll need to have at least three terminal windows open. If your terminal emulator supports tabs, consider using them to help organize your setup.
Client
Open a new terminal window.
Move into the
~/lotus-devnetdirectory:\Export the devnet-specific variables again to make sure we don’t interfere with any existing Lotus installations on your system:\
Because environmental variables are reset when you open a new terminal window, these variables must be exported every time we start a new terminal.
Start the client node using
lotus daemon:\This will output something like:\
This command will continue to run. Leave this window open.
Storage provider
Open a new terminal window.
Move into the
~/lotus-devnetdirectory:\Export the devnet-specific variables again to make sure we don’t interfere with any existing Lotus installations on your system:\
Import the genesis miner key:\
This will output something like:\
Initialize the genesis miner:\
This will output something like:\
This process take a few minutes to complete.
Start the storage provider node with
lotus-miner run:\This terminal window will continue to run. You must run all further commands from a new terminal window.
We now have a client node and a storage provider node successfully talking to each other! Next up, we can send requests to our client node to ensure everything is set up correctly.
Get some FIL
Now that we’ve got our local devnet running let’s create a new wallet and send some funds from our miner account to that new wallet.
Create a wallet
There are multiple ways to create a new wallet. The simplest way is to use the Lotus CLI directly:
Open a new terminal window.
Move into the
~/lotus-devnetdirectory:\Export the devnet-specific variables again to make sure we don’t interfere with any existing Lotus installations on your system:\
Create a new wallet with
lotus wallet new:\This will output something like:\
View the wallets available on this node with
lotus wallet list:\This will output something like:\
You can now close this terminal window, or you can keep it open for the next section.
Send funds
We can now send FIL from the pre-mined t3q4o7g... account to our new t1snly7... account with lotus send:
If you closed the terminal windows from the last section, open a new terminal window, move into the
~/lotus-devnetdirectory, and export the devnnet-specific variables again with:\View the wallets available on this node with
lotus wallet list:\This will output something like:\
In the above example, the
t3q4o...address is the pre-mined address we created in an earlier step. This has a very large balance of FIL. We want to send FIL from this pre-mined address to our newt1snl...address.Create the send request with
lotus send, supplying the pre-minedt3q4o...address as the--fromaddress, the newt1snl...address as the receiving address, and the amount of FIL we want to send:\For example:\
Check the balance of your new
t1snl...address withlotus wallet balance:\For example:\
You can now close this terminal window, or you can keep it open for the next section.
Stop and restart
You’ll eventually want to stop your local devnet from running or may need to restart it. Follow these steps.
Stop the devnet
Open the storage provider terminal window.
Press
CTRL+cto stop the node. The node will printGraceful shutdown successfulonce it has fully stopped:\This will output something like:\
You can now close the storage provider terminal window.
Open the client terminal window.
Press
CTRL+cto stop the node. The node will printGraceful shutdown successfulonce it has fully stopped:\You can now close the client terminal window.
Restart the devnet
Open a new terminal window, move into the
~/lotus-devnetdirectory, and export the devnnet-specific variables again with:\Start the client node with
lotus daemon:\This will output something like:\
This command will continue to run. Leave this window open.
For the storage provider node, open a new terminal window, move into the
~/lotus-devnetdirectory, and export the devnnet-specific variables again with:\Restart the storage provider node with
lotus-miner run:\This will output something like:\
This command will continue to run. Leave this window open.
You must run all further commands from a new terminal window.
Next steps
To summarize, you’ve started a local devnet, funded a new address, and exported that address to a file! You’ve got all the pieces ready to start developing applications on Filecoin!
Troubleshooting
Running into issues? Check out these troubleshooting steps to figure out what’s going on.
Could not get API info for FullNode
You may encounter the following error message:
If you receive this error when trying to call your Lotus daemon, either your lotus daemon isn’t running (see Restart the devnet) or you haven’t re-exported the necessary variables (see the Build section).
Last updated
Was this helpful?