How to Set up a Fantom Node to Use RPC

NOWNodes
4 min readJul 7, 2022

--

Fantom is a decentralized, permissionless and open-source smart contract platform supporting decentralized applications (dApps) that is intended to aid developers in the creation of decentralized applications (dApps) or other digital assets.

Fantom is known for its reliability, security, and high-performance. The network offers 1-second transaction finality with an average transaction fee of about $0.01. The network launched in 2018, and has provided 100% uptime.

Key Features:

  • Fantom’s EVM-compatibility means that developers accustomed to Ethereum-based frameworks can use popular, common tools to seamlessly deploy smart contract solutions on the Fantom network.
  • Fantom achieves exceptionally high speed through the use of a hybrid Directed Acyclic Graph (DAG) data structure.
  • Fantom’s concensus algorithm Lachesis is secure, scalable, and provides true asynchronous Byzantine Fault Tolerance (aBFT).
  • The Fantom ecosystem features a wide range of dApps including Decentralized Finance protocols (DeFi), Metaverse spaces, NFT marketplaces, games, and more.

Why use Fantom Node

Fantom nodes seamlessly connect dApps to the Fantom network to enable transactions across the ecosystem.

What is RPC?

An RPC is a straightforward API, enabling independent developers to communicate with nodes and execute code remotely. A server is referred to as a node within the blockchain space.

In short, blockchain RPC nodes are needed to communicate with the blockchain, and anyone can host one themselves.

RPC nodes allow users to read blockchain data and send transactions to different networks. This means that an RPC node is vital when it comes to enabling a decentralized application (dApp) to function properly.

Without the possibility to send an RPC call, no dApp can interact with the blockchain.

Running Fantom Node to use RPC

We will be building a Fantom Node to use RPC, step-by-step, so let’s dive in.

First, we will need a few things. Here is what you need to do:

wget https://golang.org/dl/go1.18.3.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.18.3.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
source ~/.bashrc
cd ~
go version

Then you can clone the GitHub and make the go-opera binary:

Afterward, you can put the Opera binary in the main home folder so that you can keep track of which version you are on. To find your IP address for the initial go-opera synchronization, use this command:

Now, prepare Cloudflare and your Domain text. You can replace the 111’s with your IP address.

./opera /-genesis mainnet.g -nat extip:111.111.111.111 -nousb -http -http.vhosts=”*”
-http.corsdomain=”*” -ws -ws.origins=”*”
-http.api=”ftm,eth,debug,web3,net,txpool,sfc”

Next, set up Cloudflare with TLS/SSL, and make a subdomain with a record that points to your IP address:

Navigate to SSL/TLS; next, click on Origin Server, and Create Certificate. You can use the default or specify the full subdomain.

You can create a certificate for the domain and click on “Next”, then copy the info here.

You can then insert Origin Certificate into cert.pem.

Then you can insert a Private Key into key.pem

Then you can install nginx

Use the default tile to editor:

Now, if you want to set up the https and web socket in the default file, you can use the following:

server {
listen 80;
listen [::]:80;
server_name rpc.denarius.pro;
return 302
https://$server_name$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl http2;
ssl on;
ssl_certificate /etc/ssl/certs/cert.pem;
ssl_certificate_key /etc/ssl/private/key.pem;
location ^~ /ws {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection “upgrade”;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 86400s;
proxy_send_timeout 86400s;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass
http://127.0.0.1:18546/;
}
location ^~ / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection “upgrade”;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass
http://127.0.0.1:18545/;
}
}

Now you can restart nginx:

Afterward, you can load up MetaMask and point the network to your new domain, and that is all there is to it.

Note that you can also set up a read-only node on Fantom to use as an RPC without Cloudflare but on your own dedicated server.

Final Words

Hopefully, now you know a bit more when it comes to setting up a Fantom node as a means of starting to use RPC.

This procedure is straightforward, and by following the step-by-step guide, you will be able to complete the process less than an hour.

That said, if you do not want to manually do this, you can always utilize the blockchain-as-a-service provider NOWNodes as a means of connecting to a pre-configured Fantom (FTM) node or block explorer, where all you need to do is connect through an API key.

Originally published at https://nownodes.io on July 7, 2022.

--

--