Actions

Gnosis RPC endpoint: Difference between revisions

From Chainlink Community Wiki

No edit summary
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
== [[File:GnosisXDaiLogo.png|frameless|45x45px]]This is a general guide on deploying an Fantom RPC endpoint for your Chainlink Node(s). ==
== [[File:GnosisXDaiLogo.png|frameless|45x45px]]This is a general guide on deploying an Gnosis/ xDai RPC endpoint for your Chainlink Node(s). ==
[https://github.com/Fantom-foundation/go-opera#readme Official Fantom Docs are available here]
[https://github.com/openethereum/openethereum Official xDai/Gnosis Docs are available here]


{{:Box-round|title=NOTE|This document assumes base operating system is Debian 10}}
{{:Box-round|title=NOTE|This document assumes base operating system is Debian 10}}




== Fantom RPC Endpoints: ==
== Gnosis/xDai RPC Endpoints: ==


* Websocket
* Websocket
Line 18: Line 18:
we'll install some packages that we'll need or will at least be handy to have.
we'll install some packages that we'll need or will at least be handy to have.


<code>sudo apt install -y git curl wget jq node-ws telnet traceroute</code>
<code>sudo apt install -y git curl wget jq node-ws telnet traceroute build-essential cmake libudev-dev</code>


=== Install Go ===
=== Install Go ===
Line 73: Line 73:




== Download & Install Fantom Node Software ==
== Download & Install Gnosis/xDai Node Software ==
First we'll need to clone the go-opera repository
First we'll need to clone the openethereum repository


<code>git clone <nowiki>https://github.com/Fantom-foundation/go-opera.git</nowiki></code>
<code>mkdir ~/xdai</code>


<code>cd ~/xdai</code>


Once cloned, we'll change directories into the newly downloaded go-opera directory
<code>git clone <nowiki>https://github.com/openethereum/openethereum.git</nowiki></code>


<code>cd go-opera</code>
 
 
Once cloned, we'll change directories into the newly downloaded openethereum directory
 
<code>cd openethereum</code>




Then, we'll compile the necessary binary
Then, we'll compile the necessary binary


<code>make opera</code>
<code>cargo build --release --features final</code>




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


<code>./build/opera version</code>
<code>./target/release/openethereum --version</code>




== Create Fantom Node Service ==
== Create Gnosis/xDai Node Service ==
Create a new service file for your fantom node.
Create a new service file for your xDai node.


<code>sudo nano /etc/systemd/system/fantom-node.service</code>
<code>sudo nano /etc/systemd/system/xdai-node.service</code>




Line 104: Line 109:
We'll want to update the <username> to your correct value.
We'll want to update the <username> to your correct value.
<pre style="white-space:pre-wrap; width:100%; border:1px solid lightgrey; background:black; color:white;">[Unit]
<pre style="white-space:pre-wrap; width:100%; border:1px solid lightgrey; background:black; color:white;">[Unit]
Description=Fantom Full Node
Description=OpenEthereum Daemon for xDai/Gnosis Chain
After=network.target auditd.service
After=network.target auditd.service
Wants=network.target
Wants=network.target
 
[Service]
[Service]
Type=simple
Type=simple
User=<username>
User=<username>
WorkingDirectory=/home/<username>/go-opera/
WorkingDirectory=/home/<username>/xdai/
TimeoutStartSec=0
TimeoutStartSec=0
TimeoutStopSec=120
TimeoutStopSec=120
ExecStart=/home/<username>/go-opera/build/opera \
ExecStart=sh /home/<username>/xdai/openethereum/target/release/openethereum \
--genesis /home/<username>/go-opera/build/mainnet.g \
--chain xdai \
--cache 8192 \
--jsonrpc-port=8545 \
--verbosity 2 \
--jsonrpc-cors=all \
--metrics \
--jsonrpc-interface=all \
--http \
--jsonrpc-hosts=all \
--http.addr 0.0.0.0 \
--jsonrpc-apis=all \
--http.vhosts '*' \
--ws-interface=all \
--ws \
--ws-apis=all \
--ws.addr 0.0.0.0 \
--ws-origins=all \
--ws.origins 0.0.0.0 \
--ws-hosts=all \
--datadir /home/<username>/go-opera/opera/
--ws-max-connections=10 \
Restart=always
--max-peers=100
RestartSec=10s
 
KillSignal=SIGTERM
[Install]
TimeoutStopSec=300
WantedBy=multi-user.target
Restart=always
RequiredBy=swarm.service
RestartSec=20s
Alias=fantom-node.service</pre>
 
[Install]
WantedBy=multi-user.target
RequiredBy=swarm.service
Alias=xdai-node.service</pre>




== Start Fantom Node Service ==
== Start Gnosis/xDai 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.
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.


Line 142: Line 151:
Then,
Then,


<code>sudo systemctl start fantom-node.service</code>
<code>sudo systemctl start xdai-node.service</code>




== Check Status of Fantom Node Service ==
== Check Status of Gnosis/xDai Node Service ==
We can check the status of the service itself by checking the system logs for the specific service
We can check the status of the service itself by checking the system logs for the specific service


<code>sudo journalctl -u fantom-node.service</code>
<code>sudo journalctl -u xdai-node.service</code>




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.
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.
Here's a simple bash script that does exactly that.<pre style="white-space:pre-wrap; width:100%; border:1px solid lightgrey; background:black; color:white;">#!/bin/bash
# blue foreground
blue_fg=$(tput setaf 6)
# reset to default
reset=$(tput sgr0)
 
# SET VARS
XDAI_BLOCK_HEIGHT=$(curl -s -H "Content-Type: application/json" http://localhost:8545 -d '{"jsonrpc": "2.0", "id": 123, "method": "eth_blockNumber"}' | jq -r .result)
XDAISCAN_BLOCK_HEIGHT=$(curl -sb -H "Accept: application/json" "https://blockscout.com/xdai/mainnet/api?module=block&action=eth_block_number" | jq -r .result)


''be sure to add your api key in place of <api_key>''
PEER_COUNT=$(curl -s -H "Content-Type: application/json" http://localhost:8545 -d '{"jsonrpc":"2.0","method":"net_peerCount","params":[],"id":74}' | jq -r .result)
<pre style="white-space:pre-wrap; width:100%; border:1px solid lightgrey; background:black; color:white;">#!/bin/bash
IS_SYNCING=$(curl -s -H "Content-Type: application/json" http://localhost:8545 -d '{"jsonrpc": "2.0", "id": 123, "method": "eth_syncing"}' | jq .)
   
   
# blue foreground
echo "----------------------"
blue_fg=$(tput setaf 6)
echo "RPC Node Current Block: ${blue_fg}$((XDAI_CURRENT_BLOCK))${reset}"
# reset to default
echo ""
reset=$(tput sgr0)
echo "XDAI Scan block height: ${blue_fg}$((XDAISCAN_BLOCK_HEIGHT))${reset}"
echo "Current peer count:    ${blue_fg}$((PEER_COUNT))${reset}"
   
   
# SET VARS
VAR1=$(curl -s -H "Content-Type: application/json" <nowiki>http://localhost:18545</nowiki> -d '{"jsonrpc": "2.0", "id": 123, "method": "eth_syncing"}' | jq .result)
FTM_BLOCK_HEIGHT=$(curl -s -H "Content-Type: application/json" <nowiki>http://localhost:18545</nowiki> -d '{"jsonrpc": "2.0", "id": 123, "method": "eth_blockNumber"}' | jq -r .result)
VAR2="false"
FTMSCAN_BLOCK_HEIGHT=$(curl -s -d "action=eth_blockNumber&apikey=<api_key>&module=proxy" -X POST <nowiki>https://api.FtmScan.com/api</nowiki> | jq -r .result)
 
FTM_CURRENT_BLOCK=$(curl -s -H "Content-Type: application/json" <nowiki>http://localhost:18545</nowiki> -d '{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":74}' | jq -r .result.currentBlock)
FTM_HIGHEST_BLOCK=$(curl -s -H "Content-Type: application/json" <nowiki>http://localhost:18545</nowiki> -d '{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":74}' | jq -r .result.highestBlock)
IS_SYNCING=$(curl -s -H "Content-Type: application/json" <nowiki>http://localhost:18545</nowiki> -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" <nowiki>http://localhost:18545</nowiki> -d '{"jsonrpc": "2.0", "id": 123, "method": "eth_syncing"}' | jq .result)
VAR2="false"
   
   
if [ "$VAR1" = "$VAR2" ]; then
if [ "$VAR1" = "$VAR2" ]; then
     echo "Sync Status:          ${blue_fg}Node is synced.${reset}"
     echo "Sync Status:          ${blue_fg}Node is synced.${reset}"
else
else
     echo "${blue_fg}Node is ${yellow_fg}NOT${blue_fg} synced.${reset}"
     echo "${blue_fg}Node is ${yellow_fg}NOT${blue_fg} synced.${reset}"
fi</pre>
fi</pre>

Latest revision as of 15:57, 11 April 2022

GnosisXDaiLogo.pngThis is a general guide on deploying an Gnosis/ xDai RPC endpoint for your Chainlink Node(s).

Official xDai/Gnosis Docs are available here

NOTE

This document assumes base operating system is Debian 10


Gnosis/xDai 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 build-essential cmake libudev-dev

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 Gnosis/xDai Node Software

First we'll need to clone the openethereum repository

mkdir ~/xdai

cd ~/xdai

git clone https://github.com/openethereum/openethereum.git


Once cloned, we'll change directories into the newly downloaded openethereum directory

cd openethereum


Then, we'll compile the necessary binary

cargo build --release --features final


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

./target/release/openethereum --version


Create Gnosis/xDai Node Service

Create a new service file for your xDai node.

sudo nano /etc/systemd/system/xdai-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=OpenEthereum Daemon for xDai/Gnosis Chain
After=network.target auditd.service
Wants=network.target

[Service]
Type=simple
User=<username>
WorkingDirectory=/home/<username>/xdai/
TimeoutStartSec=0
TimeoutStopSec=120
ExecStart=sh /home/<username>/xdai/openethereum/target/release/openethereum \
--chain xdai \
--jsonrpc-port=8545 \
--jsonrpc-cors=all \
--jsonrpc-interface=all \
--jsonrpc-hosts=all \
--jsonrpc-apis=all \
--ws-interface=all \
--ws-apis=all \
--ws-origins=all \
--ws-hosts=all \
--ws-max-connections=10 \
--max-peers=100

KillSignal=SIGTERM
TimeoutStopSec=300
Restart=always
RestartSec=20s

[Install]
WantedBy=multi-user.target
RequiredBy=swarm.service
Alias=xdai-node.service


Start Gnosis/xDai 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 xdai-node.service


Check Status of Gnosis/xDai Node Service

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

sudo journalctl -u xdai-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.

#!/bin/bash
 
# blue foreground
blue_fg=$(tput setaf 6)
# reset to default
reset=$(tput sgr0)

# SET VARS
XDAI_BLOCK_HEIGHT=$(curl -s -H "Content-Type: application/json" http://localhost:8545 -d '{"jsonrpc": "2.0", "id": 123, "method": "eth_blockNumber"}' | jq -r .result)
XDAISCAN_BLOCK_HEIGHT=$(curl -sb -H "Accept: application/json" "https://blockscout.com/xdai/mainnet/api?module=block&action=eth_block_number" | jq -r .result)

PEER_COUNT=$(curl -s -H "Content-Type: application/json" http://localhost:8545 -d '{"jsonrpc":"2.0","method":"net_peerCount","params":[],"id":74}' | jq -r .result)
IS_SYNCING=$(curl -s -H "Content-Type: application/json" http://localhost:8545 -d '{"jsonrpc": "2.0", "id": 123, "method": "eth_syncing"}' | jq .)
 
echo "----------------------"
echo "RPC Node Current Block: ${blue_fg}$((XDAI_CURRENT_BLOCK))${reset}"
echo ""
echo "XDAI Scan block height: ${blue_fg}$((XDAISCAN_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