How to set up a Filecoin Lotus node and connect remotely to it
Tags: blockchain, filecoin, ethereum, blockchaindevelopmen
Published: 2020-11-11 21:00:35

---
title: How to set up a Filecoin Lotus node and connect remotely to it
published: true
date: 2020-11-09 08:28:10 UTC
tags: blockchain,filecoin,ethereum,blockchaindevelopmen
canonical_url: https://medium.com/coinmonks/how-to-set-up-a-filecoin-lotus-node-and-connect-remotely-to-it-208c2f810060
---

![](https://cdn-images-1.medium.com/max/718/1*EdeLaxve4VTYs4YrTweRLw.jpeg)

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](https://docs.filecoin.io/get-started/lotus/installation/) 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>
```

Now we can connect to the EC2 instance:

```
ssh -i <path-to-pem-file> ubuntu@<ip-of-your-instance>
```

#### 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
```

Rustp:

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

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
```

#### 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
```

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
```

Source the file or restart the terminal:

```
source ~/.bashrc
```

#### 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)
```

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
```

Build and install

```
make clean all
sudo make install
```

Check the version:

```
lotus --version #should output something like lotus version 1.1.0+git.b039f44a
```

#### 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"
```

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
```

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

```
lotus auth create-token --perm admin
```

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')
```

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}
```

#### 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
```

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
```

Start the daemon from pm2

```
pm2 start start-lotus-daemon.sh
```

And monitor it whenever we want:

```
pm2 monit
```

#### 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](https://www.wfil.network/#/) 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](https://twitter.com/swarooph) and [Mostafa](https://www.linkedin.com/in/mostafa-farghaly) for all the help in this process.

#### Also, Read

- The Best [Hardware wallet](https://medium.com/coinmonks/the-best-cryptocurrency-hardware-wallets-of-2020-e28b1c124069?source=friends_link&sk=324dd9ff8556ab578d71e7ad7658ad7c)

* * *