How to set up a Chainlink Node?

set up chainlink node

Blockchain has witnessed a staggering rise in popularity, with decentralization and security as its valuable traits. However, the ability of blockchain to maintain the integrity by limiting the input data from external sources faced some limitations. So, it exhibited the need to introduce a bridge to help blockchain networks acquire input from different sources without disrupting its decentralized nature.

It is how chainlink came into existence and acquired a lot of traction as a decentralized oracle technology. Hence, unlike other oracle designs that rely on centralized gateways, chainlink is developed on a network of independent node operators offering unique integrations to numerous blockchain applications.

According to Digital coin, it is anticipated that the chainlink will be trading at $31.64 in 2021. Moreover, the value of LINK is predicted to reach as high as $44.91 by the end of 2024. This article sheds light on the significance of chainlink fundamentals and the necessary steps to establish a chainlink node by answering the following questions:

 

  • What is Chainlink Node?
  • Why is Chainlink necessary?
  • What are the technical requirements to operate the Chainlink Node?
  • How to set up a Chainlink Node?

What is Chainlink Node?

 

Chainlink is a decentralized platform network that provides real-world datasets like events, data feeds and information to smart contracts via oracles from off-blockchain sources to on blockchain. It enables smart contracts to interact securely with real-world data and services existing outside the blockchain networks. Smart contracts are pre-specified agreements on the blockchain that evaluate information and execute when certain conditions are met. In chainlink, LINK tokens are used as digital assets to pay for services on the network.

Chainlink plays an important role in bridging the gap between traditional data and the future of blockchain technology. It enables smart contracts to interface with real-world information, providing them with secure access to key data resources. Thus, chainlink offers reliable, tamper-proof inputs and outputs on any blockchain network. The key areas of focus to enable chainlink network include:

  • Improving smart contracts ecosystem to build better blockchain applications.
  • Building the improved reference implementation of chainlink.
  • Providing access to data, payments and other API services.

Why is chainlink necessary?

 

Chainlink aims to solve the smart contract connectivity problem. This problem refers to an inability of a smart contract to interact with any other resources running outside the node network. When smart contracts need to deal with off-chain data, this data must be in a similar format as on-chain data. The difficulty of connecting the outside data to blockchain in such a language that both on-chain and off-chain sources can understand limits the usability of smart contracts.

As a result, the oracle was introduced into the blockchain ecosystem to bring about off-chain data to on-chain. Oracle plays a crucial role in retrieving and providing external data to the blockchain and smart contracts through APIs. As centralized oracles reduced the blockchain benefits due to faulty and alterable nature, chainlink came into existence.

Chainlink offers a wide range of decentralized services to smart contracts such as:

  • Price feed (financial market data of DeFi economy).
  • Verifiable randomness (creating dynamic NFTs and on-chain gaming apps).
  • Proof-of-reserve ( offers proof of off-chain collateral that is backing stablecoins and cross-chain tokens).
  • Keeper network (autonomous DevOps Services).

What are the technical requirements to operate Chainlink Node?

Chainlink node exhibit a minimal set of hardware requirements to operate. It can run with 1core, 1 to 2 GB RAM for better reliability. Connectivity is highly essential to establish communication between the Ethereum client and the blockchain. If you prefer to run your own Ethereum client, you will need to run it on a separate machine. 

There are few technical requirements within the chainlink set up for smooth and reliable operation. A chainlink node operator needs the following core components to deliver external data to smart contracts. Each chainlink node operator interacts with the following mentioned components regularly. Altogether, they build up a chainlink node and allow the secure delivery of data to any blockchain.

  • Chainlink Node client software 

    It is an open-source infrastructure that bridges the on-chain and off-chain environments.

  • On-chain oracle contract 

    The smart contracts of the chainlink node track the data queries and generate responses back to the user’s smart contract requests.

  • Data source subscriptions 

    Chainlink nodes must connect with the off-chain data source APIs to fetch data to request smart contracts.

  • External monitoring systems

    Peripheral off-chain infrastructure is essential to monitor the performance and reliability of a Chainlink node in real-time.

How to set up a chainlink node?

 

Setting up the chainlink node involves two methods. The first method is to install all required development dependencies, download the code base, and compile a binary on your local machine. The second method involves running a Docker image by updating it as a part of the continuous delivery process.

Here, the article focuses on incorporating the second method using Docker with the steps given below.

Infographic for insight article How to set up a chainlink node

Step 1: Docker CE Installation

The first and foremost step is Docker-CE installation. Docker-CE (community edition) represents a free version of Docker used to spin up containers without any need to pay for enterprise-level support. It continuously builds and deploys the code from the repository on Github.

On clicking the Docker-CE link, select the operating system, follow the instructions and complete the installation process.

Following commands will help in docker installation for windows, Mac OS and Ubuntu.

For Windows and macOS:

Docker-CE comes with Docker Desktop, which can be downloaded from Docker hub, install Docker Desktop and open the Docker.app to run the Docker.

For Ubuntu:

$ curl -sSL https://get.docker.com/ | sh

sudo usermod -aG docker $USER

exit

Step 2: Creating PostgreSQL database

For running a Chainlink node, it is essential to use PostgreSQL as an open-source database with high data integrity, extensibility and speed. This database can be built by itself or provided by cloud service providers. In addition, it offers compatibility for ACID transactions and supports dynamic loading.

To set up the PostgreSQL database instance with Easy Create, follow the steps mentioned below.

Step 1: Sign in to AWS Management Console and open the RDS console at https://console.aws.amazon.com/rds/.

Step 2: Choose the AWS region to create a DB instance in the RDS console and choose ‘Databases’ in the navigation pane.

Step 3: Select Create database and ensure that you choose Easy Create.

Step 4: Choose PostgreSQL in configuration and Free tier for selecting DB instance size.

Step 5: Enter a name for the DB instance identifier, or use the default name.

Step 6: Enter the Master username and the database gets created.

Step 7: On selecting the “Autogenerate a password” checkbox, the master password gets generated automatically for the DB instance.

Step 8: Clear Auto-generate a password checkbox, enter the same password in Master password and confirm it.

Step 9: On opening the “View default settings” for Easy create, you can examine and change the necessary settings.

Step 10: Select “Create database” and choose the name of the new PostgreSQL DB instance. The details for the newly created DB instance appear on the RDS console.

Step 3: Set an Ethereum Client

Besides creating PostgreSQL, a chainlink needs to have an active WebSocket connection to an Ethereum client for communicating with smart contracts on the blockchain. Therefore, Docker can be of great significance to have an Ethereum client running and synced before starting the Chainlink node. It is possible with the help of Geth, Parity or a third-party connection.

Geth and Parity provide official images through Docker, which are easy to run. Both of them follow similar fundamental stages like downloading the image, creating a volume, running the image. The following steps show how to run Geth and Parity in their official Docker containers for each network they support.

Run the command given below to download the Geth (ethereum/client-go) Docker image

docker pull ethereum/client-go:stable

This command downloads the Geth client to run as a containerized application on a local machine.

When the chainlink node connects with the Ethereum client node, it receives the user Oracle request on the chain via the connected Ethereum client and writes the obtained data to the chain by submitting the transaction. Hence, the chainlink node depends completely on the Ethereum client node for functionality. It is possible to build your own Ethereum client node or choose the Ethereum RPC service provider. There could be two possible cases for running Ethereum clients.

Case 1:  When the Ethereum client runs on the same machine, get the IP address of the container on which the ethereum client is running with the help of the command given below.

ETH_CONTAINER_IP=$(docker inspect –format ” $(docker ps -f name=eth -q))

Then, add etherenm client’s URL to the environment file by executing the following command.

echo “ETH_URL=ws://$ETH_CONTAINER_IP:8546” >> ~/.chainlink/.env

While using an external Ethereum client, use the External tab below, and update$ETH_CONTAINER_IP to the WebSocket address used for connectivity.

echo “ETH_URL=ws://$ETH_CONTAINER_IP:8546” >> ~/.chainlink/.env

Case 2: Ethereum Client as an External Provider

While using an external provider for connectivity to the Ethereum blockchain or running an Ethereum client on a separate instance, use the command given below for your network to update the value forCHANGEME to the value given by the provider or the address and port of the separate instance.

echo “ETH_URL=CHANGEME” >> ~/.chainlink/.env

Step 4: Create a chainlink directory

After setting up the Ethereum client, create a directory for blockchain data to avoid the necessity of re-syncing the overall blockchain each time while restarting the image. The directory gets created with the help of the following command.

mkdir ~/.geth-ropsten

This command creates an empty directory that is used for Geth’s Docker image whenever it is executed. On running the image, assign parameters to connect it with the chainlink node.

Now, enable the WebSockets to establish a secure connection with the chainlink node with the command given below.

docker run –name eth -p 8546:8546 -v ~/.geth-ropsten:/geth -it \\

ethereum/client-go:stable –testnet –syncmode light –ws \\

–wsaddr 0.0.0.0 –wsorigins=”*” –datadir /geth`

Then, assign the name ‘eth’ to a container with the help of a created directory to run on the Ropsten test network. It also enables the running of Ethereum client on light mode to keep the blockchain data minimal. It is advisable to avoid running a light client on Ethereum main net due to security concerns.

The commands are almost similar in the case of running parity client instead of Geth. The difference exists only between the image and directory. For example, running the following command will help you to download the latest parity Docker image.

docker pull parity/parity:stable

Then, prefer creating a persistent directory for Parity:

mkdir ~/.parity-ropsten

After that, run the Parity image with the following code.

docker run -h eth –name eth -p 8546:8546 \\

-v ~/.parity-

ropsten:/home/parity/.local/share/io.parity.ethereum/ \\

-it parity/parity:stable –chain=ropsten \\

–ws-interface=all –ws-origins=”all” –light \\

–base-path /home/parity/.local/share/io.parity.ethereum/

Once the Ethereum client completes syncing, it is possible to run the Chainlink node.

Similar to the steps with the Ethereum client, initially download the latest Chainlink image from Docker:

docker pull smartcontract/chainlink:latest

Here, the tag “latest” is used to update and maintain the code repository on Github. However, it is equally important to create the persistent directory for the chainlink node in the following manner.

mkdir ~/.chainlink-ropsten

Ropsten: mkdir ~/.chainlink-ropsten

Step 5: Configure environment variables / file

The next steps involve the setup configuration for the chainlink node. Chainlink makes use of environment variables for configuration. Before initiating for the node to run, it is necessary to create a file to pass into the Docker image containing desired values. This file gets created by running the following code for Mac and Linux operating systems.

echo “ROOT=/chainlink

LOG_LEVEL=debug

ETH_URL=ws://eth:8546

ETH_CHAIN_ID=3

MIN_OUTGOING_CONFIRMATIONS=2

MIN_INCOMING_CONFIRMATIONS=0

LINK_CONTRACT_ADDRESS=0x20fe562d797a42dcb3399062ae9546cd06f63280

CHAINLINK_TLS_PORT=0

CHAINLINK_DEV=true

ALLOW_ORIGINS=*” > .env

The values for the “ETH_CHAIN_ID” and “LINK_CONTRACT_ADDRESS” are inserted corresponding to values specific to the Ropsten test network. Therefore, while running the code on a different network, these values are changeable.

Therefore, the file gets saved with the name “.env.”

Step 6: Start running the node.

After configuring the environment variables, run the chainlink node using the following code.

docker run –link eth -p 6688:6688 \\

-v ~/.chainlink-ropsten:/chainlink \\

-it –env-file=.env \\

smartcontract/chainlink local n

This code initiates the Chainlink node using the previously created values stored in the environment file and links to the running Ethereum client’s Docker image.

For running the chainlink node for the first time, the administrator must set the Keystore password confirmation of the node account. It is important to keep note of this password. If it gets lost, there is no way to retrieve it and the funds managed by the private key also get lost. Each time you start, you need to enter this password to unlock the Keystore. The node requires to sign the transaction through the private key of the Keystore and submit it to the blockchain.

Chainlink node is used to manage the Ethereum keys instead of the Ethereum client. Thus, it removes the need to run the ethereum client with an unlocked account while the JSON-RPC port is open. The chainlink keys play a crucial role in signing transactions, which would answer requests for smart contracts. It also requires some ETH to write to the blockchain. Once the node displays the Ethereum address, you can get Response ETH for it.

Then, the node administrator must enter the details of email accounts and passwords to log in to the node management page. These details are required for interacting with the Chainlink node through the API, command-line, or the GUI. So, the user needs to enter an email and a strong password, preferably different than the Keystore password, to complete the setup process. Then, the Ethereum node completes syncing before the Chainlink node becomes completely operational.

After completing these steps, the chainlink node starts running and receiving block headers from the Ethereum client. Pointing your browser to http://localhost:6688/, you can see the GUI.

Step 7: Login browser management page

On opening the IP:6688 address in the browser, the login entry of the chainlink node management page becomes visible. Then, login into the management interface with the email account and password. Hence, the admin dashboard becomes visible and now, the user acts as a node operator.

Then, go to the “Configuration” tab, where you will find oneAccount_ADDRESS. This address represents the address corresponding to the private key of the Keystore password that you need to set while initializing the node. Before providing the services, it transfers this address to ‘eth’ for submitting transactions.

As you prefer the Ropsten test network, you can copy this address to the Ropsten faucet for getting the test eth. In an application serving Ethernet, you need to transfer the account address to ‘eth’ manually.

Step 8: Generate an oracle contract.

Oracle contract acts as a bridgehead of the chainlink node on the blockchain. It helps to communicate with the user contract directly, receive the Oracle request from the user, and write the request result to the user’s contract through the callback function registered by the user.

The oracle contract does not exhibit the need to write the contracts. Instead, the user can directly deploy the open-source Oracle contract code of chainlink. While deploying with remix, the user needs to create a new file comprising the following command.

pragma solidity 0.6.6;

import “https://github.com/smartcontractkit/chainlink/evm-contracts/src/v0.6/Oracle.sol“;

Generally, the Oracle contract accepts the link fee temporarily paid by the user for initiating the chainlink request. Therefore, it is essential to maintain the private key of the contract owner properly.

Once the Oracle contract is deployed, open permissions are given to the node’s address to allow the node to execute transactions.

Step 9: Add Jobs

At the node management interface, open the “jobs” tab and click “new job,” then copy the JSON of each type of job into the text box.

Later, replace the JSON in JSON with the deployed oracle contract address like YOUR_ORACLE_CONTRACT_ADDRESSField. Each job creates a job ID. Hence; all the jobs become visible in the ‘jobs’ tab.

Step 10: Test node availability

The eventual step involves testing the availability of deployed chainlink node service with the following code.

pragma solidity ^0.6.0;

import “https://raw.githubusercontent.com/smartcontractkit/chainlink/develop/evm-contracts/src/v0.6/ChainlinkClient.sol”;

contract APIConsumer is ChainlinkClient {

uint256 public ethereumPrice;

address private oracle;

bytes32 private jobId;

uint256 private fee;

constructor() public {

setPublicChainlinkToken();

//Insert the Oracle address we just deployed

oracle = 0x5F66a231a29CE1513dc6c16407fDCe9D0aEE2cB0;

//Enter the address we just created

jobId = “4b9b6e7d89154a8d855affed3985aafd”;

//The minimum fee paid to Oracle becomes visible in the configuration page minimum_ CONTRACT_ View the payment field

fee = 1 * 10 ** 18; // 1 LINK

}

 

function requestEthereumPrice() public returns (bytes32 requestId)

{

Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfill.selector);

 

//Assign API address to be requested

request.add(“get”, “https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD“);

 

//The resolution path of the API return the result value

request.add(“path”, “USD”);

 

//Multiply the result value for eliminating the decimal point

request.addInt(“times”, 100);

 

//Sending the request

return sendChainlinkRequestTo(oracle, request, fee);

}

 

function fulfill(bytes32 _requestId, uint256 _price) public recordChainlinkFulfillment(_requestId)

{

ethereumPrice = _price;

}

}

Chainlink serves as an important oracle network to bridge the blockchain to the real world in a decentralized manner. It works actively to facilitate the smart contracts for quick implementation and secured interaction with an ample collection of external inputs and outputs in the form of on-chain contracts. Apart from enabling the interaction between the smart contracts and external systems, it allows the smart contracts to extend the use cases across a more diverse set of markets.

Chainlink technology holds immense potential for DeFi and other crypto ecosystems. With a high level of security, transparency and trust, delivering the data through an open network of nodes becomes feasible, thereby allowing anyone to run their node, participate in Chainlink staking, and provide data to smart contracts. Therefore, chainlink can be used for numerous applications which can benefit from the transparency, efficiency, and security of blockchain-based smart contracts.

If you are looking to set up a chainlink node or overcome blockchain oracle issues, reach out to our experts, who can actively assist you with our Chainlink blockchain development services. So, connect with our team to explore the full chainlink potential for your business requirements.

 

Author’s Bio

Akash Takyar
Akash Takyar
CEO LeewayHertz
Akash Takyar is the founder and CEO at LeewayHertz. With the experience of building over 100+ platforms for startups and enterprise allows Akash to rapidly architect and design solutions that are scalable and beautiful.
Akash's ability to build enterprise-grade technology solutions has attracted over 30 Fortune 500 companies, including Siemens, 3M, P&G and Hershey’s. Akash is an early adopter of new technology, a passionate technology enthusiast, and an investor in AI and IoT startups.

Start a conversation by filling the form

Once you let us know your requirement, our technical expert will schedule a call and discuss your idea in detail post sign of an NDA.

All information will be kept confidential.

 Send me the signed Non-Disclosure Agreement (NDA)