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.
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.
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.
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:\
Install Rust:\
Source the ~/.cargo/env
config file:\
Install the following dependencies:\
Install Go and add /usr/local/go/bin
to your $PATH
variable:\
You may need to export /usr/local/go/bin
to 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/env
config file:
Done! You can move on to the Pre-build section.
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-devnet
directory:\
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-devnet
directory:\
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.
Create the 2k
binary 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!
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.
Open a new terminal window.
Move into the ~/lotus-devnet
directory:\
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.
Open a new terminal window.
Move into the ~/lotus-devnet
directory:\
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.
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.
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-devnet
directory:\
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.
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-devnet
directory, 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 new t1snl...
address.
Create the send request with lotus send
, supplying the pre-mined t3q4o...
address as the --from
address, the new t1snl...
address as the receiving address, and the amount of FIL we want to send:\
For example:\
Check the balance of your new t1snl...
address with lotus wallet balance
:\
For example:\
You can now close this terminal window, or you can keep it open for the next section.
You’ll eventually want to stop your local devnet from running or may need to restart it. Follow these steps.
Open the storage provider terminal window.
Press CTRL
+ c
to stop the node. The node will print Graceful shutdown successful
once 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
+ c
to stop the node. The node will print Graceful shutdown successful
once it has fully stopped:\
You can now close the client terminal window.
Open a new terminal window, move into the ~/lotus-devnet
directory, 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-devnet
directory, 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.
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!
Running into issues? Check out these troubleshooting steps to figure out what’s going on.
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).
Test funds are available to developer so that they can test their smart contracts and applications within the confines of a test network. This page covers how to get test funds from a local testnet.
Before we begin, you must have a local testnet running. Follow the Run a local network guide if you haven’t got a local testnet set up yet.
Change directory to where you created the lotus
and lotus-miner
binaries. If you followed the Run a local network guide these binaries will be in ~/lotus-devnet
:\
View the wallets available on this node with lotus wallet list
:\
This command will output something like:\
Create the send request with lotus send
, supplying the pre-mined t3q4o...
address as the --from
address, the new t1snl...
address as the receiving address, and the amount of FIL we want to send:\
For example:\
This command will output something like:\
Check the balance of your new t1snl...
address with lotus wallet balance
:\
For example:\
This command will output something like:\
If you want to manage your local testnet tokens in MetaMask you will need to create a t4
address. You can create a t4
address using lotus wallet new deleated
. Once you have a t4
address you can connect MetaMask to your local testnet to see the new balance within the MetaMask extension.