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

BigQuery Chainlink (Testnet)

This Chainlink has a dedicated connection to Google's BigQuery API for retrieving the Ethereum gas price.

Steps for using this oracle

Chainlink Network Details

You will need to use the following LINK token address, oracle address, and Job ID in order to create the Chainlink request.

Ropsten

LINK Token address: 0x20fE562d797A42Dcb3399062AE9546cd06f63280
Oracle address: 0x658E48c412F85939Ef5b977f00d3a3D9796ca9e6
JobID: 4f35b80476e14202ac742182ee556447

Kovan

LINK token address: 0xa36085F69e2889c224210F603D836748e7dC0088
Oracle address: 0x2f90A6D021db21e1B2A077c5a37B3C7E75D15b7e
JobID: 14d31bb7c28546e3af7d3cef604b3a2c

Create your Chainlinked contract

Import ChainlinkClient.sol into your contract so you can inherit the ability to create Chainlink requests.

pragma solidity ^0.4.24;

import "chainlink/contracts/ChainlinkClient.sol";

contract BigQueryChainlink is ChainlinkClient {
  
  uint256 oraclePayment;

  constructor(uint256 _oraclePayment) public {
    setPublicChainlinkToken();
    oraclePayment = _oraclePayment;
  }
  // Additional functions here:
  
}

Tasks

Request Parameters

action

Required

The action to perform, available values:

  • date (default)
  • block

Solidity example

req.add("action", "date");

block

Required when action is block

The Ethereum main net block to retrieve information about.

Solidity example

req.addUint("block", 7000000);

date

Required when action is date

The date to aggregate the gas price.

Solidity example

req.add("date", "2019-05-15");

endpoint

Options:

  • gas-price (default)
  • eth-price
  • address-attributes

The endpoint to reach out to.

Solidity example

req.add("endpoint", "eth-price");

addr

Required when endpoint is address-attributes

The address to retrieve aggregates for.

Solidity example

req.add("addr", "0x87002564F1C7b8F51e96CA7D545e43402BF0b4Ab");

copyPath

Required

The path of the desired data field to return to the smart contract.

Solidity example

req.add("copyPath", "gasPrice");

times

The number to multiply the result by (since Solidity can't handle decimal places).

Solidity example

req.addInt("times", 100);

Chainlink Examples

This example shows how to create the request for the Chainlink node:

function requestGasPriceByBlock(address _oracle, bytes32 _jobId, uint256 _block)
  public
  onlyOwner
{
  Chainlink.Request memory req = buildChainlinkRequest(_jobId, this, this.fulfillGasPrice.selector);
  req.add("action", "block");
  req.addUint("block", _block);
  req.add("copyPath", "gasPrice");
  sendChainlinkRequestTo(_oracle, req, oraclePayment);
}
function requestGasPriceByDate(address _oracle, bytes32 _jobId, string _date)
  public
  onlyOwner
{
  Chainlink.Request memory req = buildChainlinkRequest(_jobId, this, this.fulfillGasPrice.selector);
  req.add("action", "date");
  req.add("date", _date);
  req.add("copyPath", "gasPrice");
  req.addInt("times", 1000);
  sendChainlinkRequestTo(_oracle, req, oraclePayment);
}
function requestEthPriceByDate(address _oracle, bytes32 _jobId, string _date)
  public
  onlyOwner
{
  Chainlink.Request memory req = buildChainlinkRequest(_jobId, this, this.fulfillEthPrice.selector);
  req.add("endpoint", "eth-price");
  req.add("action", "date");
  req.add("date", _date);
  req.add("copyPath", "high");
  req.addInt("times", 1000);
  sendChainlinkRequestTo(_oracle, req, oraclePayment);
}
function requestAddressAttributes
(
  address _oracle,
  bytes32 _jobId,
  string _date,
  string _path,
  string _addr
)
  public
  onlyOwner
{
  Chainlink.Request memory req = buildChainlinkRequest(_jobId, this, this.fulfillAddressAttributes.selector);
  req.add("endpoint", "address-attributes");
  req.add("date", _date);
  req.add("copyPath", _path);
  req.add("addr", _addr);
  req.addInt("times", 1000);
  sendChainlinkRequestTo(_oracle, req, oraclePayment);
}

Here is an example of the fulfillGasPrice method:

int256 public gasPrice;

function fulfillGasPrice(bytes32 _requestId, int256 _gasPrice)
  public
  recordChainlinkFulfillment(_requestId)
{
  gasPrice = _gasPrice;
}
int256 public ethPrice;

function fulfillEthPrice(bytes32 _requestId, int256 _ethPrice)
  public
  recordChainlinkFulfillment(_requestId)
{
  ethPrice = _ethPrice;
}
int256 public usage;

function fulfillAddressAttributes(bytes32 _requestId, int256 _usage)
  public
  recordChainlinkFulfillment(_requestId)
{
  usage = _usage;
}

BigQuery Chainlink (Testnet)


Suggested Edits are limited on API Reference Pages

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