Chainlink Oracles: How to get Off-Chain

Apr 7, 2023

floating cubes

There are several parts of the Chainlink architecture that are involved in helping your smart contract get off-chain and retrieve data from or interact with an API.

You’ll hear about

  • Smart contacts

  • Jobs

  • External Adapters

  • Bridges

  • Chainlink Nodes

  • Node Operators

  • Oracles

  • Decentralized Oracle Networks (DONs)

Do you need all these components and where do they live ?

What’s the bare minimum needed to get off-chain?

The basics components needed for enabling a smart contract to fetch some data off-chain, e.g from a REST API are:

  • your smart contract running on an EVM-compatible blockchain

  • an oracle, specifically an oracle contract

  • a Chainlink node

  • a job on that node

I’m assuming you know what a smart contract is… Its a piece of code running on the blockchain that’s going to change the world !

An oracle contract is another smart contract on the same blockchain, with smaller aspirations than your contract, which acts as the intermediary for the node you’re about to use to fetch some off-chain data.

A Chainlink node is a server somewhere on the public internet that talks to the blockchain and listens outs for _things to do_. You, as a smart contract developer, do not need to run your own node. Other people, in fact whole teams, are dedicated to fulfilling that role. You’ll find node operators to help you in the operator-requests channel on Chainlink’s Discord.

I mentioned things to do… these are known as jobs, which are executed inside a Chainlink node. A node operator configures their node to do a whole variety of different jobs:

  • fetch data from a JSON API

  • post data to a JSON api

  • run a cron job

  • fetch ETH/USD price

  • move expensive compute off-chain

  • fetch off-chain DAO votes

The node operator will publish their Oracle ID and the Job ID enabling your smart contract to send requests to their node.

On the mainnets you’ll need to pay the node operator with LINK tokens on a per job transaction basis. Remember to transfer enough LINK tokens from your own wallet to your smart contract address.

The calls to the oracle contract are asynchronous…meaning you won’t get a direct reply. Several seconds or minutes later the node will write back any answers via its oracle contract to your calling smart contract. The cost of this “reply” transaction is covered by the node operator and is paid for in the native currency of the blockchain, e.g. ETH or MATIC.

So what about External Adapters?

External Adapters (EAs) perform the complex heavy lifting that you can’t accomplish from a smart contract with a simple GET or POST request. EAs are not a required component but they are very useful.

They help accomplish:

  • chaining together multiple JSON API interactions

  • converting data to a more digestible format for your smart contract

  • hiding API keys used for accessing remote JSON APIs

External Adapters are typically hosted as cloud functions or run from a Docker container. They can be written by anyone with traditional API development skills.

To configure the use of an External Adapter a node operator has to perform two steps:

  1. Configure a bridge from their node to the external adapter.

  2. Refer to the bridge in the job configuration file.

Decentralised Oracle Networks (DONs) – the final piece in the puzzle

Up until now we’ve discussed all the components need to get off-chain. Chainlink’s architecture offers one final component that enables a higher degree of decentralisation.

Using the components mentioned above you could’ve created a price feed that combined data from multiple high quality trusted sources. You would’ve constructed a job that queried the APIs of numerous sources using EAs and calculated an average of the answers you received.

However your single oracle could be perceived as a single source of truth and hence a weak point in certain scenarios.

For critical scenarios like price feeds which underpin all of DeFi, Chainlink allows node operators to combine forces into a Decentralised Oracle Network DON. The networks combine multiple oracles – often 30 or more, run by independent highly-skilled teams, to determine the answers to questions posed – such as what is the ETH/USD price?