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.

Kovan

LINK token address: 0xa36085F69e2889c224210F603D836748e7dC0088
Oracle address: 0x2f90A6D021db21e1B2A077c5a37B3C7E75D15b7e
Int256 JobID: 14d31bb7c28546e3af7d3cef604b3a2c
Uint256 JobID: 2702448d062042b6a174a1f24017618d

Create your Chainlinked contract

Import Chainlinked.sol into your contract so you can inherit the Chainlinked behavior.

pragma solidity ^0.4.24;

import "chainlink/contracts/ChainlinkClient.sol";

contract BQChainlink is ChainlinkClient {
  bytes32 constant GAS_PRICE_JOB_ID = bytes32("14d31bb7c28546e3af7d3cef604b3a2c");
  bytes32 constant ETH_PRICE_JOB_ID = bytes32("2702448d062042b6a174a1f24017618d");
  constructor() public {
    setChainlinkToken(0xa36085F69e2889c224210F603D836748e7dC0088);
    setChainlinkOracle(0x2f90A6D021db21e1B2A077c5a37B3C7E75D15b7e);
  }
  // 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", toString("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(uint256 _block)
  public
  onlyOwner
{
  Chainlink.Request memory req = buildChainlinkRequest(GAS_PRICE_JOB_ID, this, this.fulfillGasPrice.selector);
  req.add("action", "block");
  req.addUint("block", _block);
  req.add("copyPath", "gasPrice");
  sendChainlinkRequest(req, ORACLE_PAYMENT);
}
  function requestGasPriceByDate(string _date)
    public
    onlyOwner
  {
    Chainlink.Request memory req = buildChainlinkRequest(GAS_PRICE_JOB_ID, this, this.fulfillGasPrice.selector);
    req.add("action", "date");
    req.add("date", _date);
    req.add("copyPath", "gasPrice");
    req.addInt("times", 1000);
    sendChainlinkRequest(req, ORACLE_PAYMENT);
  }
function requestEthPriceByDate(string _date, string _path)
  public
  onlyOwner
{
  Chainlink.Request memory req = buildChainlinkRequest(ETH_PRICE_JOB_ID, this, this.fulfillEthPrice.selector);
  req.add("endpoint", "eth-price");
  req.add("action", "date");
  req.add("date", _date);
  req.add("copyPath", _path);
  req.addInt("times", 1000);
  sendChainlinkRequest(req, ORACLE_PAYMENT);
}
function requestAddressAttributes(string _date, string _path, addresss _addr)
  public
  onlyOwner
{
  Chainlink.Request memory req = buildChainlinkRequest(ETH_PRICE_JOB_ID, this, this.fulfillAddressAttributes.selector);
  req.add("endpoint", "address-attributes");
  req.add("date", _date);
  req.add("copyPath", _path);
  req.add("addr", toString(_addr));
  req.addInt("times", 1000);
  sendChainlinkRequest(req, ORACLE_PAYMENT);
}

Here is an example of the fulfillGasPrice method:

int256 public gasPrice;

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

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

function fulfillAddressAttributes(bytes32 _requestId, uint256 _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.