Chainlink Developers

Welcome to the Chainlink documentation site. You'll find comprehensive guides and documentation to help you start working with Chainlink as quickly as possible, as well as support if you get stuck. Click here for an introductory walkthrough on how to create a Chainlink request on the Ropsten test network!

Building on Chainlink? Click here to get started!

Get Started

Using Chainlink Reference Data Contracts

Chainlink reference data contracts are on-chain reference points for external data that can be widely relied on across a smart contract network. These contracts are updated on a regular basis by multiple Chainlink nodes. This page will teach you how to make use of them.

Import Chainlink into Your Project

In order to make it easy to use the reference data contracts, you can import Chainlink NPM package into your Solidity project.

npm install chainlink --save
yarn add chainlink

Also see Create a Chainlinked Project for additional ways to use Chainlink contracts in your project.

Inherit the AggregatorInterface in Your Contract

Import the AggregatorInterface.sol contract into the source of the contract you want to consume reference data.

import "chainlink/contracts/interfaces/AggregatorInterface.sol";

Specify the Address of the Reference Contract

Set the address of the reference contract that contains the reference data you wish to consume.

AggregatorInterface internal reference;

function setReferenceContract(address _aggregator)
  public
  onlyOwner()
{
  reference = AggregatorInterface(_aggregator);
}
AggregatorInterface internal reference;

constructor(address _aggregator) public {
  reference = AggregatorInterface(_aggregator);
}

Use the Reference Data

Now that your contract is pointing towards a reference contract, you're ready to consume the data.

function getLatestPrice() public view returns (int256) {
  return reference.currentAnswer();
}

You can also check the block height at which the reference data was last updated.

function getLatestUpdateHeight() public view returns (uint256) {
  return reference.updatedHeight();
}

Complete Example

Below is a brief but complete example of a consuming contract of Chainlink reference data.

pragma solidity 0.4.24;

import "chainlink/contracts/interfaces/AggregatorInterface.sol";

contract ReferenceConsumer {
  AggregatorInterface internal reference;

  constructor(address _aggregator) public {
    reference = AggregatorInterface(_aggregator);
  }

  function getLatestPrice() public view returns (int256) {
    return reference.currentAnswer();
  }

  function getLatestUpdateHeight() public view returns (uint256) {
    return reference.updatedHeight();
  }
}

Live Reference Data Contracts (Ethereum Mainnet)

All the currentAnswer value for all reference data contracts is multiplied by 100000000 before being written on-chain.

Below are the available reference data contracts by their pairing and the address which the data is available. You can point the AggregatorInterface to any address below in order to retrieve the latest reference data on Ethereum mainnet.

Test Reference Data Contracts (Ropsten)

Below are the available reference data contracts on the Ropsten test network.

Test Reference Data Contracts (Rinkeby)

Below are the available reference data contracts on the Rinkeby test network.

Using Chainlink Reference Data Contracts


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.