For Those Who Never Chainlink

Kseniya Lifanova
Upstate Interactive
6 min readMay 21, 2020

The Oracle Problem?

Simply put, an oracle is a provider of data.

In the blockchain realm, an oracle is what feeds information from the outside world to a smart contract. Smart contracts are self-executing applications that live on the blockchain and do something when triggered.

If a smart contract relies on outside data to run some type of function, we must ensure the data provided is secure, accurate, and has not been tampered with.

Relying on one source of data creates a single point of failure. If an oracle provides false data to the smart contract and the smart contract executes based on that data, we have ourselves an “oracle problem.”

“The security of any system is only as strong as its weakest link, so a highly trustworthy oracle is required to preserve the trustworthiness of a well-engineered blockchain.” — Chainlink Whitepaper

What is Chainlink?

Chainlink is a decentralized oracle network. It exists to help connect smart contracts to real-world data in a highly secure and reliable way. It kills the single point of failure and eliminates the oracle problem.

How does it work?

Chainlink is run by a network of nodes that provide information to and from the blockchain. You can think of it as middleware between the blockchain and an external API.

If a smart contract needs information from an API, it would make a request to a node or nodes in the Chainlink network. Those nodes would make the API call, evaluate the data, and return it back to the smart contract. The nodes are incentivized to provide truthful data through LINK tokens. A purchaser of data (the smart contract) must send LINK tokens when requesting outside data.

Architecture

The Chainlink network consists of an on-chain and off-chain architecture.

Chainlink Architecture Diagram

On-chain, a requesting smart contract (Requester) interfaces with a Chainlink oracle contract to make a request for data. The Requester Contract sends LINK tokens and data for the request. The on-chain oracle contract receives the LINK tokens and request and emits an event to the off-chain Chainlink network.

Off-chain, Chainlink nodes are connected to the Ethereum blockchain and monitoring events. A Chainlink node will pick up an event and perform a request to an external API. The API returns data, which the Chainlink node returns back to the on-chain oracle. The oracle aggregates the responses and passes them back as a single response to the requesting contract.

External adapter

External adapters are not always necessary to use with the Chainlink network, but provide developers with the ability to customize an API response. They are also used with private APIs that require a secret key to be sent along with the request.

External adapters live between the Chainlink node and an external API and communicate with a simple JSON specification. They can be written in any language.

Chainlink Architecture with External Adapter

Decentralization

The Chainlink network allows users to easily customize their integration with the system. To maximize decentralization and help protect an application against faulty nodes, a user can use the following approaches: distribution of sources and distribution of oracles.

Distribution of sources

To protect against a single faulty data source, you can tell your oracle contract to collect data from multiple sources. Rather than using one API, use three APIs and aggregate the results.

Distribution of sources

Distribution of oracles

To take it a step further, you can use multiple nodes to collect data from a source or from multiple sources. This provides greater decentralization as you are not relying on any one single node.

Distribution of oracles and sources

Our use case

At Upstate Interactive, we’ve been working on a decentralized application that needs results from an external API. Since the results will trigger a payout to users on the platform, we integrated Chainlink to provide us with an accurate and trustworthy data feed. For maximum decentralization, we chose three external APIs and three nodes for providing the data we needed.

We wrote a requester contract with a function that would make a request to three separate nodes. The three API providers we selected required an API key so we wrote an external adapter to safely store the key and make the API calls.

We aggregated the responses within the adapter and if two out of the three responses agreed, we sent the response back to the smart contract. If they did not agree, we sent back an error. If all went well, payouts would be executed based on the results.

Our thoughts on Chainlink

We believe that Chainlink plays an important role in the blockchain ecosystem.

Most applications use some kind of external data, and as decentralized applications become more ubiquitous, the need for accessing secure data from the outside world will become increasingly important. This is particularly true in the DeFi (decentralized finance) space, where many of the protocols depend on accurate price feeds.

Before Chainlink, DeFi projects created their own oracles that were responsible for aggregating off-chain price data and sending it to their smart contracts. As we’ve learned, this presents a risk as the protocol is relying on one centralized source of data.

Over the past year, we’ve seen several popular DeFi protocols integrate with Chainlink including Synthetix, Aave, and bZx.

To learn more about how Chainlink is helping the DeFi ecosystem, we recommend this article.

The future

Chainlink is vital to the success of decentralized applications and continued iteration and development is a must. The system outlined in their whitepaper is not fully functional on mainnet yet, but work continues to be done.

For example, service level agreements and pluggable aggregations are still being worked on. Service level agreements will allow users to specify the service criteria they are looking for (external data, timeframe, node requirements) and the agreement will assist with selecting the nodes that fulfill those requirements.

As of today, you can use the distributed oracle model but with a predetermined list of nodes that you assign on-chain.

Working with Chainlink

Overall, we had a good experience working with Chainlink. As with all new technologies, there is a learning curve which can sometimes be frustrating. However, the Chainlink team does a great job of providing educational resources and community support.

There is extensive documentation, a GitHub repo full of coding examples, and their top developers are available on Gitter and Discord to help you with anything you are stuck on. You can tell this is a team that truly believes in what they do and cares about the community!

Guess what? We made a video! Check it out on YouTube and click the subscribe button!

Need to integrate with Chainlink?

Upstate Interactive is a software consultancy that builds custom web and mobile applications and decentralized applications. If you are looking to integrate your DApp with Chainlink and need help, reach out to us at team@upstateinteractive.io 💜

☞ Follow us on Medium, Twitter, and LinkedIn

☞ Follow me on Twitter @devgirlla

☞ Sign up for our monthly newsletter below

Sources

--

--