Deploying a working Chainlink node using Chainstack in minutes

This article first appeared in Coinmonks.

Chainlink nodes are oracles that allow Smart Contracts that reside on the Ethereum Blockchain to interact with external APIs. Prior to the creation of Chainlink nodes, it was impossible for Smart Contract to access these APIs, thus limiting their functionality.

The importance of Chainlink nodes cannot be underestimated — smart contracts can now be much more fluid & flexible, allowing it to truly be smart by accessing data sets from outside the blockchain.

In this tutorial, we will deploy our own Chainlink node and then seamlessly get it to connect to an Ethereum node created via Chainstack (I work there). This will be done on the Ropsten network.

Nodes created by Chainstack only need minutes to fully sync, meaning that your Chainlink node can be quickly deployed as well.

Requirements

  1. Install Docker-CE
  2. A Chainstack node (14-day trial)
  3. A PostgreSQL database

Endpoint

Let’s start by getting the websocket endpoint of your Ethereum node. This can easily be obtained from your Chainstack console. If you’re not sure on how to create an Ethereum node on Chainstack, visit my previous tutorial.

Take note of the WSS (websocket) endpoint:

Endpoints page in the Chainstack console

Running your Chainlink node

First, let’s create the directory where your Chainlink node will reside.

mkdir ~/.chainlink-ropsten

Next, create the .env file for the Docker image

echo "ROOT=/chainlink
LOG_LEVEL=debug
ETH_CHAIN_ID=3
MIN_OUTGOING_CONFIRMATIONS=2
LINK_CONTRACT_ADDRESS=0x20fe562d797a42dcb3399062ae9546cd06f63280
CHAINLINK_TLS_PORT=0
SECURE_COOKIES=false
ALLOW_ORIGINS=*" > ~/.chainlink-ropsten/.env

The “LINK_CONTRACT_ADDRESS” variable is set to “0x20fe562d797a42dcb3399062ae9546cd06f63280” , which is the contract address for test Chainlink tokens on the Ropsten testnet. Thus, change this accordingly when using other testnets or mainnet.

Since we’re running the Ethereum client on Chainstack and not on a local machine, copy & edit the code below with your WSS endpoint.

echo "ETH_URL=WSS_ENDPOINT" >> ~/.chainlink-ropsten/.env

where WSS_ENDPOINT is the value obtained from the Chainstack console.

Creating a PostgreSQL database

For information on how to run a managed PostgreSQL database with popular cloud providers, see Chainlink Docs: Connecting to a Remote Database.

If you would like to set up your own PostgreSQL database, follow an example for Ubuntu in Setting up a Chainlink node with an Ethereum node provided by Chainstack.

Add your PostgreSQL database connection details to the .env file for the Docker image:

echo "DATABASE_URL=postgresql://SUPERUSER:[email protected]_ADDRESS:PORT/DATABASE_NAME" >> ~/.chainlink-ropsten/.env

where

  • SUPERUSER — the PostgreSQL database superuser.
  • PASSWORD — the password for the superuser.
  • IP_ADDRESS — the IP address of the machine where you run your PostgreSQL database.
  • PORT — use the default PostgreSQL port 5432.
  • DATABASE_NAME — the database name you created for the superuser.

Starting the node

Run the code below in your terminal:

cd ~/.chainlink-ropsten && docker run -p 6688:6688 -v ~/.chainlink-ropsten:/chainlink -it --env-file=.env smartcontract/chainlink local n

Congratulations, your node should be running! Your terminal window should look something like this:

Creation of a Chainlink node

Chainlink nodes will manage and use their own Ethereum keys, and will not use the Ethereum keys managed by the Ethereum client. You will be prompted for a password, and this password represents the Ethereum Keystore file used by your Chainlink node.

Once you’ve set the node password, you can create the first API user for your Chainlink node. As an API user, you will be able to create new jobs for smart contracts to make API calls to.

Once the API user is created, the Chainlink node should receive block headers from the Chainstack Ethereum node:

Chainlink listening to Chainstack

That’s it! You can also log in to your Chainlink console http://localhost:6688 to add in jobs.

Conclusion

Feel free to play around and deploy your own jobs and interact with the node.

See also a full walkthrough for Ubuntu: Setting up a Chainlink node with an Ethereum node provided by Chainstack.

You can head over to the Chainlink documentation on how to fulfill requests.


Explore Chainstack

Perspectives with Paul Sitoh – part 1

We sat down with Paul Sitoh virtually, with him in London and us in Singapore. Paul has extensive experience working on blockchain and cloud technologies…In this inaugural two-part interview as part of Chainstack’s Perspectives series on our blog, we discuss his journey into the world of the blockchain…

Chainstack
Chainstack
Dec 21
Chainstack uses cookies to provide you with a secure and
personalized experience on its website. Learn more.