Experience of studying Avalanche

Oleg Familov
8 min readApr 6, 2021

Most recently, I had an Avalanch experience and I want to tell you about it.
It all started when a friend of mine told me that a cool stuff is going on at figment with Avalanch and told me that in just one day you can build a whole network and conduct a transaction using only the terminal and JavaScript.

It all started with registering on DataHub, but this is nothing difficult, I think you will figure it out for yourself :)
After all this, we go to Figment and select Avalanch.

We select the first task available to us:

(There will be a “Start” button, but I have already completed this task, so I cannot show how it looks — this is punishable)

Then we read the entire introduction, install all the necessary components such as Node JS and preferably VS Code for convenient work, and then create a folder for our task.

The folder is created in one word and with a small letter it is necessary!
Write:

node -v

and make sure our version is greater than 12.
The next command would be:

npm init -y

Which initializes all the necessary files in our directory.

We should see the following code in the package.json file.
Let’s start installing all the packages we need, they will be used throughout all the following steps, so in no case we will not delete them:

Avalanche — for interacting with the Avalanche API
Dotenv — for managing environment variables

We register the following command to install all packages:

npm install — save avalanche dotenv

You need to register it in the terminal if we use VS Code.

After successful installation, you will also see the packages added to your file: package.json

These are new lines that were added after the successful installation of all the necessary components.
The most important and probably the most difficult of all the training, the setup will happen now!
We create an .env file in the directory of our program and add these lines there:

NODE_URL=https://avalanche--fuji--rpc.datahub.figment.io

NODE_API_KEY=YOUR_API_KEY

NETWORK_ID=5

NETWORK_NAME=fuji

In the place of YOUR_API_KEY, we insert our API key from the datahub, in order to get it, we go to the page and copy.

Never show yours to anyone .env file because it contains your API and an attacker can use it to harm you!

Checking our network connectivity to DataHub and Avalanch:

We create a client.js file inside the project and throw the following code into it, we can make a beautiful tabulation in it, so that everything is beautiful.
We should get the following result:

// Load environment variables
require(“dotenv”).config()

// Load Avalanche SDK components
const { Avalanche } = require(“avalanche”)

if (!process.env.NODE_URL) throw “NODE_URL env var is not set!”
if (!process.env.NODE_API_KEY) throw “NODE_API_KEY env var is not set!”
if (!process.env.NETWORK_ID) throw “NETWORK_ID env var is not set!”
if (!process.env.NETWORK_NAME) throw “NETWORK_NAME env var is not set!”

// Configure Avalanche client from the DataHub url
const url = new URL(process.env.NODE_URL)
const client = new Avalanche(
url.hostname,
url.port,
url.protocol.replace(“:”, “”),
parseInt(process.env.NETWORK_ID),
“X”,
“C”,
process.env.NETWORK_NAME
)

// Apply DataHub API authentication token
client.setAuthToken(process.env.NODE_API_KEY)

module.exports = client

We should get the following result:

Let’s move on to creating the next connect.js file, it sets up all the necessary connections to the Avalanche network, I’m not a JavaScript expert, but I can say that the file receives all the information about our network thanks to the installed components and outputs them to the console.
Create a connect.js file and add the following content to it:

// Load Avalanche client helper

const client = require(“./client”)

async function main() {

// Initialize the Info API client

const info = client.Info()

console.log(“Fetching network information…”)

const nodeVersion = await info.getNodeVersion()

const networkName = await info.getNetworkName()

const networkID = await info.getNetworkID()

const networkPeers = await info.peers()

console.log(“\nNetwork info:”)

console.log(“* Node version:”, nodeVersion)

console.log(“* Network name:”, networkName)

console.log(“* Network ID:”, networkID)

console.log(“* Connected Peers:”, networkPeers.length)

}

main().catch((err) => {

console.log(“We have encountered an error!”)

console.error(err)

})

This code works in conjunction with the file that we wrote above and its main purpose is to connect us to the network and display all the necessary information on the terminal console.
Here’s what we should get:

After all the manipulations, the most pleasant part comes, we run everything that we have written and are happy with the result:
We reopen the terminal and write there:

node connect.js

If everything is configured correctly, you should see the following output:

Fetching network information…

Network info:

* Node version: avalanche/1.2.0

* Network name: fuji

* Network ID: 5

* Connected Peers: [some digits]

If everything is so, then congratulations, we did everything right, which means that we can safely send our task for verification and wait for its confirmation!
Go back to our Datahub and click Verify to make sure everything is really good. After checking the task, we will see the following result:

In my picture, I have already completed all the tasks and as soon as you do the same, you will be the best Figment student and this means that they did it!

Conclusion:

All subsequent tasks are no more difficult than what we have completed now, they are very interesting and instructive and make you feel like a programmer. I want to give a huge thank you to the entire Figment and Avalanche team for providing a free crypto literacy learning opportunity and endlessly improving your skills, plus a ton of stuffs for it! I don’t know where these cool guys were before, but I want to say with confidence that I will continue to follow and participate in the development of figment. In addition to Avalanche, figment has other pathways that you can find on their website yourself and believe me — you will not be disappointed. Even when I came to these guys, I knew absolutely nothing about Node and my experience in cryptocurrency ended with participation in airdrops, but what I did later took me to a new level, I created my own network, was able to send a transaction, and also met very cool guys in the discord channel. If you have ever wanted to start understanding cryptocurrency, then it is better to do it right now with the figment io team.

Let’s take a closer look at why Avalanche is so good?

Look just out of the corner of your eye at this picture and everything will immediately become clear:

Still have questions? Okay, let’s move on!

Maybe so?

1. Consensus Engine

Avalanche has two consensus engines on launch:
Avalanche: A DAG-optimized consensus protocol–high-throughput, parallelizable, and simple to prune.
Snowman: A chain-optimized consensus protocol–high-throughput, totally-ordered, and great for smart contracts.

2. Virtual Machines (VMs)

Virtual Machines (VMs) in Avalanche are code that uses consensus to produce a database. This database can be in the form of a chain, a DAG, a logfile, or some other data structure that requires synchronization across multiple machines.
The VM logic can be deployed many times across many subnets.

3. Chains

Chains are a generic term for VM instances. Each chain is assigned a ChainID and can be part of one and only one subnet. However, the same VM instance can be used to deploy the same type of chain multiple times within a subnet.

4. Subnets

Subnets (short for “sub-network”) are a dynamic set of validators working together to achieve consensus on the state of a set of blockchains. Subnets are required to create custom incentive mechanisms for these validators.

In simpler terms, Avalanche has a perfectly configured network that can withstand huge loads, and is also made with all the convenience for scaling and deploying it on your computers. What other network would care about its friends like that?)

Avalanche Resources:

1. AvalancheGo

AvalancheGo is the official Go implementation of Avalanche and has a full suite of JSON RPCs for interacting with the virtual machine APIs on Avalanche. AvalancheGo comes replete with a local KeyStore, metrics, IPC, and Admin APIs for interacting with the node itself.

2. AvalancheJS

The Javascript library for interacting with Avalanche APIs. AvalancheJS integrates with existing decentralized applications to enable Avalanche integration. It has a modular library architecture, allowing for custom VMs to write plugins to extend AvalancheJS functionality.

3. Avash

Avash is a program written in Go that aims to enable the creation of local networks on Avalanche, quickly for your testing purposes. Avash supports Lua scripts enabling developers to automate various local networks, launch subnets, and deploy chains on these networks to integrate into CI pipelines.

4. Avalanche Wallet and Faucet

A wallet and faucet server have been open-sourced to enable developers to interact with Avalanche. Using the wallet, funds can be sent and received throughout the network. When using private shared testing environments, the faucet is useful for developers in need of funds for their own testing purposes.

In a more understandable language, Avalanche provides just a huge number of tools for participating in the development of the network. If you are suddenly familiar with Java Script, then you will understand what I mean, I think many programmers will want to try their hand at finalizing modules and commands for Avalanche.

Well, this is where my story about my experience of participating in the Avalanche and Figment io team comes to an end, I told only a small part of all the real advantages of this network, you can find all the additional information on the official Avalanche website or ask the admins in the Discord.

Links:

Avalanche main site;
Avalanche pros;
Avalanche in DataHub;
Figment Discord;
Ask me a question.

Many thanks again to Avalanche and Figment for such a cool event, guys, I’m with you!

--

--