DEV Community

loading...

How to set up a Filecoin Lotus node and connect remotely to it

coinmonks profile image CoinMonks Originally published at Medium on ・4 min read

At Wrapped Filecoin (WFIL) we are developing the first Filecoin Wrapped Token on Ethereum. To achieve our goal, we need to be able to explore and analyze Filecoin’s blockchain in detail.

Used to working with Ethereum we can quickly think about several tools to do that, but currently, Fielecoin is in a very early phase and those tools aren’t available yet.

So we decided to set up our own Lotus node and configure it to allow us to call its JSON RPC methods from our backend API. The main instructions we followed are located here: Filecoin Lotus Installation docs but since we needed to modify some of the steps, we thought it worth sharing it and help anyone with the same problem.

1. Launch a Virtual Server and connect through SSH

In our case, we use AWS as a cloud provider, so we set up an EC2 of the type m5ad.2xlarge. Here is important to select Ubuntu Server 20.04 LTS since all the tools and libraries needed to install Lotus and Go are not available on the Amazon Linux System.

To connect to the AWS instance through SSH, make sure to have configured the security group to allow remote access through port 22. After that, you should use the PEM certificate generated at the moment of launching the instance, but first, let’s set the proper permission to be able to use it:

chmod 400 <path-to-pem-file>
Enter fullscreen mode Exit fullscreen mode

Now we can connect to the EC2 instance:

ssh -i <path-to-pem-file> ubuntu@<ip-of-your-instance>
Enter fullscreen mode Exit fullscreen mode

2. Install Dependencies, Go, and Rust

There is no much to do here, we can just follow the guide on Filecoin’s website:

Dependencies:

sudo apt install mesa-opencl-icd ocl-icd-opencl-dev gcc git bzr jq pkg-config curl clang build-essential libhwloc-dev -y && sudo apt upgrade -y
Enter fullscreen mode Exit fullscreen mode

Rustp:

curl --proto '=https' --tlsv1.2 -sSf [https://sh.rustup.rs](https://sh.rustup.rs) | sh
Enter fullscreen mode Exit fullscreen mode

Go:

wget -c [https://dl.google.com/go/go1.14.7.linux-amd64.tar.gz](https://dl.google.com/go/go1.14.7.linux-amd64.tar.gz) -O - | sudo tar -xz -C /usr/local
Enter fullscreen mode Exit fullscreen mode

3. Configure environment variables

This step is not well explained in the docs and if you are not familiar with dealing with this kind of software, it can be a tricky part.

First, we should add the variables to the environment configuration. Let’s open the bash profile file:

nano ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

Add the variables for go and rust by adding the following lines at the end of the file:

export PATH=$PATH:/usr/local/go/bin
export PATH=$PATH:/home/ubuntu/.cargo/bin
Enter fullscreen mode Exit fullscreen mode

Source the file or restart the terminal:

source ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

4. Install and launch Lotus daemon

Same as before, we just execute the given commands.

Clone the repository:

git clone [https://github.com/filecoin-project/lotus.git](https://github.com/filecoin-project/lotus.git)
Enter fullscreen mode Exit fullscreen mode

Checkout the branch of your choice (mainnet or any testnet). We chose calibration since is the testnet that best simulates mainnet:

git checkout ntwk-calibration
Enter fullscreen mode Exit fullscreen mode

Build and install

make clean all
sudo make install
Enter fullscreen mode Exit fullscreen mode

Check the version:

lotus --version #should output something like lotus version 1.1.0+git.b039f44a
Enter fullscreen mode Exit fullscreen mode

5. Allow remote connections

Open the lotus config ~/.lotus/config.toml. You will see different sections to configure with examples of the values you can set. We are interested in the API Section for ListendAddress and RemoteListenAddress values. Remove their comments and set the following value to each of them:

ListenAddress = "/ip4/0.0.0.0/tcp/4001/http"
RemoteListenAddress = "/ip4/xxx.xxx.xxx.xxx/tcp/4001/http"
Enter fullscreen mode Exit fullscreen mode

Be sure to replace xxx.xxx.xxx.xxx with your instance public IP and to set the port that fits you best (also note that this port also should be opened on the security group of your EC2 instance).

Launch the daemon:

lotus daemon
Enter fullscreen mode Exit fullscreen mode

Create a token to access it remotely (p.e. as admin)

lotus auth create-token --perm admin
Enter fullscreen mode Exit fullscreen mode

Use the token to call your instance from a different computer and test everything we have done:

curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer <the-token-you-just-generated>" --data '{ "jsonrpc": "2.0", "method": "Filecoin.Version", "params": [], "id": 1 }' '[http://xxx.xxx.xxx.xxx:4001/rpc/v0'](http://54.216.161.54:5000/rpc/v0')
Enter fullscreen mode Exit fullscreen mode

The output should be a JSON response like the following:

{"jsonrpc":"2.0","result":{"Version":"1.1.0+git.b039f44a","APIVersion":4352,"BlockDelay":30},"id":1}
Enter fullscreen mode Exit fullscreen mode

6. [BONUS] setup pm2 to always start the daemon

If the instance is restarted or the daemon stops, we should be aware of it, connect to the instance, and restart the daemon. Having a library like pm2 can save you a lot of trouble in those cases and restart the daemon when needed.

To configure it you should install NodeJS, NPM, and pm2:

sudo apt install nodejs
sudo apt install npm
npm install pm2@latest -g
Enter fullscreen mode Exit fullscreen mode

Then we should create a one-line shell script to launch the daemon, configure pm2, and make it able to start it:

echo lotus daemon >> start-lotus-daemon.sh
sudo env PATH=$PATH:/usr/bin /usr/local/lib/node_modules/pm2/bin/pm2 startup systemd -u ubuntu --hp /home/ubuntu/start-lotus-daemon.sh
Enter fullscreen mode Exit fullscreen mode

Start the daemon from pm2

pm2 start start-lotus-daemon.sh
Enter fullscreen mode Exit fullscreen mode

And monitor it whenever we want:

pm2 monit
Enter fullscreen mode Exit fullscreen mode

Conclusion

Setting up your own Lotus node can seem like hard work, but having complete control of the data you can get from Filecoin’s blockchain can really worth it.

Feel free to checkout WFIL dapp and let us know any thoughts you may have. We are really hoping to build the first Filecoin Wrapped Token on Ethereum hand in hand with the community.

Special thanks to Swaroop and Mostafa for all the help in this process.

Also, Read


Discussion

pic
Editor guide