Actions

Avalanche RPC endpoint: Difference between revisions

From Chainlink Community Wiki

(Created page with "center|thumb 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 ** <code>ws://<your_ip_address>:9650/ext/bc/C/ws</code> * HTTP ** <code>http://<your_ip_address>:9650/ext/bc/...")
 
No edit summary
Line 144: Line 144:
  RequiredBy=swarm.service
  RequiredBy=swarm.service
  Alias=avax-node.service</code>
  Alias=avax-node.service</code>
Save the file and exit.
Save the file and exit.



Revision as of 17:41, 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:

  • 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

curl icanhazip.com

[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.