Actions

Avalanche RPC endpoint: Difference between revisions

From Chainlink Community Wiki

No edit summary
No edit summary
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[File:AvalanceLogo.png|left|frameless]]
[[File:AvalanceLogo.png|left|thumb]]


== Deploying Avalanche RPC Node ==
== This is a general guide on deploying an Avalanche RPC endpoint for your Chainlink Node(s). ==
[https://docs.avax.network/build/tutorials/nodes-and-staking/run-avalanche-node/ Official Avalanche Docs are available here]


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








<H2>Avalanche RPC Endpoints:</H2>
You Chainlink node has two connections methods.  Websocket and HTTP.


 
As these can vary between networks, the default values for an Avalanche node are:
This is a general guide on deploying an Avalanche RPC endpoint for your Chainlink Node(s).
 
Official Avalanche Docs are available [https://docs.avax.network/build/tutorials/nodes-and-staking/run-avalanche-node/ here]
 
Note: This document assumes base operating system is Debian 10
 
 
 
== Avalanche RPC Endpoints: ==


* Websocket
* Websocket
Line 64: Line 59:


We'll want to add the following to the bottom of the ~/.profile file
We'll want to add the following to the bottom of the ~/.profile file
<code>export GOPATH=$HOME/go
<pre style="white-space:pre-wrap; width:100%; border:1px solid lightgrey; background:black; color:white;">export GOPATH=$HOME/go
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin</code>
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin</pre>




Line 129: Line 124:
Example Contents for your .service file are below:
Example Contents for your .service file are below:


<pre>curl icanhazip.com</code>
<code>curl icanhazip.com</code>


Example contents of your .service file is below
Example contents of your .service file is below


<code>[Unit]
<pre style="white-space:pre-wrap; width:100%; border:1px solid lightgrey; background:black; color:white;">[Unit]
  Description=Avalanche RPC Node
  Description=Avalanche RPC Node
  After=network.target auditd.service
  After=network.target auditd.service
Line 180: Line 175:


If we want to check the status/state of the endpoints sync, we can simply query the RPC endpoint to see if the node is bootstrapped.
If we want to check the status/state of the endpoints sync, we can simply query the RPC endpoint to see if the node is bootstrapped.
<code>#!/bin/bash
 
<pre style="white-space:pre-wrap; width:100%; border:1px solid lightgrey; background:black; color:white;">#!/bin/bash
  curl -s -X POST --data '{
  curl -s -X POST --data '{
     "jsonrpc":"2.0",
     "jsonrpc":"2.0",
Line 188: Line 184:
         "chain":"X"
         "chain":"X"
     }
     }
  }' -H 'content-type:application/json;' 127.0.0.1:9650/ext/info | jq -r .result</code>
  }' -H 'content-type:application/json;' 127.0.0.1:9650/ext/info | jq -r .result</pre>
 
If you want to save the above as a bash script, you can run it whenever you like to see if the node is synced.
If you want to save the above as a bash script, you can run it whenever you like to see if the node is synced.

Latest revision as of 18:53, 21 March 2022

AvalanceLogo.png

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

Official Avalanche Docs are available here

NOTE

This document assumes base operating system is Debian 10



Avalanche RPC Endpoints:

You Chainlink node has two connections methods. Websocket and HTTP.

As these can vary between networks, the default values for an Avalanche node are:

  • Websocket
    • ws://<your_ip_address>:9650/ext/bc/C/ws
  • HTTP
    • http://<your_ip_address>:9650/ext/bc/C/rpc


Install Dependencies

Before we can get our Avalanche 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 Avalanche Node Software

First, we'll need to clone the avalanche-go respository

git clone git@github.com:ava-labs/avalanchego.git


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

cd avalanche-go


Then, we'll run the provided script to build the necessary pacakges

bash ./scripts/build.sh


Once the script is finished running, we can check to confirm the binary is correct but checking the version

./avalanche-go/build/avalanchego --version

You should see the installed version of the avalanchego software, avalanche/<version> [database=v<version>, commit=<commit_hash>]

Lastly, we'll create a directory for our Avalanche logs and blockchain data

mkdir -p ~/.avalanche/logs && mkdir ~/.avalanche/db


Once we've tested and confirmed the operation of the binary, we will create a service for the avalanchego binary.


Create Avalanche Node Service

Create a new service file for your avalanche node.

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


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

We'll want to update the <username> and <your_public_ip> to your correct values.

If you don't know your public IP, you can get it without leaving the command line with a simple curl command

Example Contents for your .service file are below:

curl icanhazip.com

Example contents of your .service file is below

[Unit]
 Description=Avalanche RPC Node
 After=network.target auditd.service
 Wants=network.target
 
 [Service]
 Type=simple
 User=<username>
 WorkingDirectory=/home/<username>/.avalanchego/
 TimeoutStartSec=0
 TimeoutStopSec=120
 ExecStart=/home/<username>/avalanchego/build/avalanchego \
 --network-id=mainnet \
 --public-ip=<your_public_ip> \
 --db-dir /home/<username>/.avalanchego/db \
 --http-host 0.0.0.0 \
 --log-level Warn \
 --log-dir /home/<username>/.avalanchego/logs
 Restart=always
 RestartSec=20s
 
 [Install]
 WantedBy=multi-user.target
 RequiredBy=swarm.service
 Alias=avax-node.service


Save the file and exit.


Start Avalanche 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 avax-node.service


Check Status of Avalanche Node Service

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

sudo journalctl -u avax-node.service


If we want to check the status/state of the endpoints sync, we can simply query the RPC endpoint to see if the node is bootstrapped.

#!/bin/bash
 curl -s -X POST --data '{
    "jsonrpc":"2.0",
    "id"     :1,
    "method" :"info.isBootstrapped",
    "params": {
        "chain":"X"
    }
 }' -H 'content-type:application/json;' 127.0.0.1:9650/ext/info | jq -r .result

If you want to save the above as a bash script, you can run it whenever you like to see if the node is synced.