Skip to content

Chainlink Oracles on Moonbeam

Chainlink Banner

Disclaimer: Projects themselves entirely manage the content in this guide. Moonbeam is a permissionless network. Any project can deploy its contracts to Moonbeam.

Introduction

Chainlink is a decentralized oracle network that provides reliable tamper-proof inputs and outputs for complex smart contracts on any blockchain. In simpler terms, Chainlink enables your smart contracts to access real-world data securely.

Chainlink's oracle solution is now available on the Moonbase Alpha TestNet. Two types of oracle request models are available:

  • Basic Request Model — a simple model where a user requests a transaction, and a single oracle source fulfills that request. Although simple, it relies on the user trusting the oracle source as the source of truth
  • Decentralized Data Model — adds an on-chain aggregation data, where data is aggregated from a decentralized network of independent oracle nodes. One example is Chainlink Price Feeds, which aggregate asset price data

You can read more about Chainlink in the following links:

You can contact the team via the following communication channels:

Moonbase Alpha Implementation

Chainlink oracle solution and smart contracts are currently deployed in the Moonbase Alpha TestNet with both Kovan and Rinkeby Ethereum's TestNets.

Basic Request Model

You can find all the contract's addresses that are relevant Basic Request Model in the following table:

Contract Address
Oracle Contract 0xA356990bCDed8Cc6865Be606D64E7381bfe00B72
LINK Token 0xa36085F69e2889c224210F603D836748e7dC0088

The initial request can be made by using the following Client contract, which you can deploy to the Moonbase Alpha TestNet using Remix and MetaMask. When deploying the contract, you need to provide the LINK token address.


Once deployed, you have the requestPrice() function. This function initiates the request that is fetched by the oracle via events emitted by the oracle contract. The function needs the oracle address, the job specification ID, and the payment to be sent to the oracle (for TestNet purposes, it can be set to zero). The job specification ID (job ID for short) relates to the request type you make to the oracle. The list of job IDs available is presented in the following table:

Base/Quote Job ID Reference
BTC to USD 0a1d7df6a47c417bb4d0ab561a37753e
ETH to USD ddd85cc4bab24920bc7c605b5bed3bf0
DOT to USD 93790efc1e7641a99465ea8b1c71ce7a
KSM to USD d37d9a18f92f49198ceece6d367ed77a
AAVE to USD 684981fa8e264cc1afa3e1df7fe8eecc
ALGO to USD f7a442a6365048799a30c02ac56f4440
BAND to USD 6daa1fe7ba7d421a8a76fa6c2adb1382
LINK to USD c1d6b9a159c64d3888b0e71104bdbb8d
SUSHI to USD 861c8bd8d92f42d3b21606111173cd4a
UNI to USD 14ff274fc6ac469bb3a27b34c21c0957

Once you sent a request as a transaction. The oracle will fulfill this request and write the result to the currentPrice variable.

Price Feeds

A decentralized oracle network updates price feeds. Each oracle node is rewarded for publishing the price data to an Aggregator contract. The information is only updated if a minimum number of responses from Oracle nodes are received (during an aggregation round).

The end-user can retrieve price feeds with read-only operations via a Consumer contract, referencing the correct Aggregator interface (Proxy contract). The Proxy acts as a middleware to provide the Consumer with the most up-to-date Aggregator for a particular price feed.

Each price feed can be read using a straightforward contract interface pointed to the corresponding consumer contract:

pragma solidity ^0.6.6;

interface ConsumerV3Interface {
    /**
     * Returns the latest price
     */
    function getLatestPrice() external view returns (int);

    /**
     * Returns the decimals to offset on the getLatestPrice call
     */
    function decimals() external view returns (uint8);

    /**
     * Returns the description of the underlying price feed aggregator
     */
    function description() external view returns (string memory);
}

This interface provides the following functions:

  • getLatetPrice — returns the latest price available in the consumer contract
  • decimals — returns the decimals of the corresponding price feed, as numbers in smart contracts are represented as unsigned integers
  • description — returns a brief description of the price feed being queried

Currently, there is a consumer contract for the following price pairs:

Base/Quote Consumer Contract
BTC to USD 0x2C28701f63a122CCed5E01570dB04101A078041e
ETH to USD 0xfE6676f8A96005445848632a5A2D67721d584dAd
DOT to USD 0xc4F4d983d988Ab4349E04C5bf5Da0d09Ae70D12F
KSM to USD 0x16C64b68F84328627f615BB6E98C87b1d184326C
AAVE to USD 0x8F23f3cc745993c3164Cb7a852497091A452aA6d
ALGO to USD 0x3797E7Db901c8f19ed7bfF3f600D870E15d362b0
BAND to USD 0x08E04Ee892f77585540f71B13970a9C58D5FEA9a
LINK to USD 0x4b98A257b73DE965115D8FcD8aCe76249354D994
SUSHI to USD 0x700465bF9014229875d61A74140344AF823923E7
UNI to USD 0xeBf79a4aefCFf0E55203fAdEE93417A9E040FEC1