How To Reach Your Avalanche Node from Outside

Murat Celiktepe
BCISTCenter
Published in
5 min readNov 21, 2020

Running an Avalanche node on the mainnet and the testnet is quite simple. There are lots of documents written on it. However, when we want to interact with our node from outside, that may be a little bit annoying. There is a public avalanche node that you can interact with but it is not an efficient and flexible way for development.

For example, in order to use ORTELIUS which is an Avalanche transaction indexer service, you have to set it up into your local machine and the public Avalanche node is not providing Ortelius. So, it is a better way to have your own node and reach it.

Here the service NGROK comes to help. NGROK allows you to expose a web server running on your local machine to the internet. Tell NGROK what port your web server is listening on. The idea is that after running the local node in your machine, you only need to start NGROK to listen to a specific port and expose it.

Let’s start by running the local node (assuming that you already have an Avalanche node installed and ready).

If you have not changed anything, the Avalanche node would start at http://127.0.0.1:9650 and of course, you can interact with it from a local machine. Now we should install NGROK. You can download it from here. I will be using a Linux terminal.

After downloading NGROK, open a terminal and go to the directory that NGROK was downloaded, and unzip it via this command

unzip ngrok-stable-linux-amd64.zip

The name can be different, just write the name that was downloaded and it will unzip NGROK. Then, we should set the auth token. This token can be obtained via the NGROK website. Create an account and you will see the page below.

As you see, there is the “connect your account” section which includes your auth token. Copy the code line and paste it to the terminal.

You should see a confirmation message. To test it, run this command.

./ngrok http 80

If you can see the connections page, this means that NGROK is working properly.

Now, in order to start NGROK to interact with the Avalanche node, we need to run it with the running PORT. This PORT is “9650”. Simply, kill the previous process which is exposing PORT 8 with “CTRL+C” or “CTRL+Shift+C”. Then, paste this command to start with PORT 9650.

./ngrok http 9650

http://30da2939b204.ngrok.iohttp://localhost:9650

As we can see, “http://30da2939b204.ngrok.io” is referring to your local Avalanche node. So, you can use it from outside with that link. It is the same as using “http://localhost:9650”.

Let’s try to reach the node via this link that NGROK created for you. Open a new terminal and paste these commands.

Please before running this call, replace the “127.0.0.1:9650" address with the one NGROK gave you. For example, mine is “http://30da2939b204.ngrok.io” and my command will be “http://30da2939b204.ngrok.io/ext/info”.

curl -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

I run this command from another machine and the connection is established. We can run any call provided by the Avalanche document.

Now, let’s look at how to reach Ortelius via this method. As we know, after setting up Ortelius and starting it, the node and the Ortelius service start to work concurrently. If you do not have Ortelius and you need it, take a look at my previous article. Ortelius runs on PORT 8080, so we need to start NGROK with two different PORTs simultaneously.

To do that, open a terminal and go to the directory that your NGROK is downloaded, and run the command below.

sudo nano ~/.ngrok2/ngrok.yml

The point is that we need to modify ngrok.yml file and I opened it with Nano, you can open with any text editor. After opening the .yml file, delete the tunnels section and paste this one,

tunnels:
first:
addr: 9650
proto: http
second:
addr: 8080
proto: http

Here we are identifying two different tunnels that will listen to the given PORTS. 9650 is for Avalanche node and 8080 is for Ortelius. At the end of the process .yml file should look like this.

Then save and exit from the editor. If you are an Ubuntu user, it is different to save and exit.

Now, we need to start Ortelius from the terminal.

After starting Ortelius, run this command in the terminal(you should be in the directory that you downloaded and unzip the NGROK).

ngrok start --all

If everything goes well, you should see two different links forwarded to our two local PORTS. For my example,

http://3aa901a1a9de.ngrok.iohttp://localhost:8080 (Ortelius)

http://9688027a053c.ngrok.iohttp://localhost:9650 (Avalanche node)

In order to be sure that we can also reach Ortelius via this link. Copy and paste it to a browser.

You can use this link anywhere outside of your local machine to reach servers running locally.

See you in the next article.

Murat CELIKTEPE

LinkedIn → celiktepemurat

Twitter → muratctp

--

--