Actions

Fantom RPC endpoint: Difference between revisions

From Chainlink Community Wiki

No edit summary
No edit summary
 
Line 118: Line 118:
  ExecStart=/home/<username>/go-opera/build/opera \
  ExecStart=/home/<username>/go-opera/build/opera \
  --genesis /home/<username>/go-opera/build/mainnet.g \
  --genesis /home/<username>/go-opera/build/mainnet.g \
  --cache 8192 \
--maxpeers 80 \
  --cache 15000 \
  --verbosity 2 \
  --verbosity 2 \
  --metrics \
  --metrics \

Latest revision as of 18:21, 9 January 2023

FantomLogo.png

This is a general guide on deploying an Fantom RPC endpoint for your Chainlink Node(s).

Official Fantom Docs are available here

NOTE

This document assumes base operating system is Debian 10


Fantom RPC Endpoints:

  • Websocket
    • ws://<your_ip_address>:8546
  • HTTP
    • http://<your_ip_address>:8545


Install Dependencies

Before we can get our Fantom node running, we need to install some necessary software.

we'll install some packages that we'll need or will at least be handy to have.

sudo apt install -y git curl wget jq node-ws telnet traceroute

Install Go

Navigate to the official Go download page at go.dev/doc/install, and copy the link address for the download button.

Once you have the link, we'll use wget to download it.

Please remember that the below examples have <version> in lieu of the release that was applicable at the time of writing

wget https://go.dev/dl/go<version>.linux-amd64.tar.gz


This will download the tarball, which we will see is named go<version>.linux-amd64.tar.gz.

To start, we'll want to extract the tarball

tar xvf go<version>.linux-amd64.tar.gz


Now that the packages has been extracted, we should have a new directory named, go

We'll adjust permissions on the directory, then relocate it to out /usr/local/ directory.

sudo chown -R root:root ./go

sudo mv go /usr/local/


And then, we'll modify our ~/.profile file and then force a reload of it.

nano ~/.profile


We'll want to add the following to the bottom of the ~/.profile file

export GOPATH=$HOME/go
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin


Once those lines have been added to our profile, we need to force our TTY session to load it.

source ~/.profile


We'll know all is well when we check to see the path to the command and check to see what version of Go we have installed

which go

You should get /usr/local/go/bin/go as the path to the command


go version

We should see the newly installed verison, go version go<version> linux/amd64


Download & Install Fantom Node Software

First we'll need to clone the go-opera repository

git clone https://github.com/Fantom-foundation/go-opera.git


Once cloned, we'll change directories into the newly downloaded go-opera directory

cd go-opera


Then, we'll compile the necessary binary

make opera


We can check to confirm the operation of the binary by checking the verison

./build/opera version


Create Fantom Node Service

Create a new service file for your fantom node.

sudo nano /etc/systemd/system/fantom-node.service


Copy and paste the below into the new file, modifying the necessary values

We'll want to update the <username> to your correct value.

[Unit]
 Description=Fantom Full Node
 After=network.target auditd.service
 Wants=network.target
 
 [Service]
 Type=simple
 User=<username>
 WorkingDirectory=/home/<username>/go-opera/
 TimeoutStartSec=0
 TimeoutStopSec=120
 ExecStart=/home/<username>/go-opera/build/opera \
 --genesis /home/<username>/go-opera/build/mainnet.g \
 --maxpeers 80 \
 --cache 15000 \
 --verbosity 2 \
 --metrics \
 --http \
 --http.addr 0.0.0.0 \
 --http.vhosts '*' \
 --ws \
 --ws.addr 0.0.0.0 \
 --ws.origins 0.0.0.0 \
 --datadir /home/<username>/go-opera/opera/
 Restart=always
 RestartSec=10s
 
 [Install]
 WantedBy=multi-user.target
 RequiredBy=swarm.service
 Alias=fantom-node.service


Start Fantom Node Service

Once we have the service file created, we can start it with a simple command, but first, we'll reload our daemons to be sure that it detects the newly created service file.

sudo systemctl daemon-reload

Then,

sudo systemctl start fantom-node.service


Check Status of Fantom Node Service

We can check the status of the service itself by checking the system logs for the specific service

sudo journalctl -u fantom-node.service


If we want to check the status/state of the endpoints sync, we can simply query the RPC endpoint to see what the block height is, and compare that against the explorer.

Here's a simple bash script that does exactly that.

be sure to add your api key in place of <api_key>

#!/bin/bash
 
 # blue foreground
 blue_fg=$(tput setaf 6)
 # reset to default
 reset=$(tput sgr0)
 
 # SET VARS
 FTM_BLOCK_HEIGHT=$(curl -s -H "Content-Type: application/json" http://localhost:18545 -d '{"jsonrpc": "2.0", "id": 123, "method": "eth_blockNumber"}' | jq -r .result)
 FTMSCAN_BLOCK_HEIGHT=$(curl -s -d "action=eth_blockNumber&apikey=<api_key>&module=proxy" -X POST https://api.FtmScan.com/api | jq -r .result)
 FTM_CURRENT_BLOCK=$(curl -s -H "Content-Type: application/json" http://localhost:18545 -d '{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":74}' | jq -r .result.currentBlock)
 FTM_HIGHEST_BLOCK=$(curl -s -H "Content-Type: application/json" http://localhost:18545 -d '{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":74}' | jq -r .result.highestBlock)
 IS_SYNCING=$(curl -s -H "Content-Type: application/json" http://localhost:18545 -d '{"jsonrpc": "2.0", "id": 123, "method": "eth_syncing"}' | jq .)
 
 echo "----------------------"
 echo "RPC Node Current Block: ${blue_fg}$((FTM_CURRENT_BLOCK))${reset}"
 echo "RPC Node Highest Block: ${blue_fg}$((FTM_HIGHEST_BLOCK))${reset}"
 echo ""
 echo "RPC Node block height: ${blue_fg}$((FTM_BLOCK_HEIGHT))${reset}"
 echo "FTM Scan block height: ${blue_fg}$((FTMSCAN_BLOCK_HEIGHT))${reset}"
 #echo "Current peer count:    ${blue_fg}$((PEER_COUNT))${reset}"
 
 VAR1=$(curl -s -H "Content-Type: application/json" http://localhost:18545 -d '{"jsonrpc": "2.0", "id": 123, "method": "eth_syncing"}' | jq .result)
 VAR2="false"
 
 if [ "$VAR1" = "$VAR2" ]; then
     echo "Sync Status:           ${blue_fg}Node is synced.${reset}"
 else
     echo "${blue_fg}Node is ${yellow_fg}NOT${blue_fg} synced.${reset}"
 fi