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

Amberdata Chainlink (Testnet)

Chainlink has a dedicated connection to Amberdata's API. This Chainlink is able to retrieve data for any free API endpoint from Amberdata's Market Data and Blockchain Data.

A complete example project of a contract using this Chainlink is available here!

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.

Rinkeby

LINK Token address: 0x01be23585060835e02b77ef475b0cc51aa1e0709
Oracle address: 0x7AFe1118Ea78C1eae84ca8feE5C65Bc76CcF879e
Bool JobID: eb3b27aac93e4bf68406f164b86b049e
Bytes32 JobID: be55468973f94ea98e5bfc7a0e56f564
Int256 JobID: b792227af9854f809e86f7075f59a281
Uint256 JobID: 31bde5db37db4c0f86aa11e52366dc43
Raw Bytes Job ID: 18e81484db084f8e8ec77e8859802949

Kovan

LINK Token address: 0xa36085F69e2889c224210F603D836748e7dC0088
Oracle address: 0x2f90A6D021db21e1B2A077c5a37B3C7E75D15b7e
Bool JobID: 81c63592d97a4485b1d1339b3578e07f
Bytes32 JobID: dc6f14c1179a47ffa3977bcf766ce309
Int256 JobID: c915dfec8ad6487289ea98dc3f22c1cb
Uint256 JobID: 956db887488348b59b72dc8caa551385
Raw Bytes Job ID: 004b6663bb314419ab4ba1fd80b5de99

Create your Chainlinked contract

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

pragma solidity ^0.4.24;

import "@chainlink/contracts/src/v0.4/ChainlinkClient.sol";

contract AmberdataChainlink is ChainlinkClient {
  
  uint256 oraclePayment;
  
  constructor(uint256 _oraclePayment) public {
    setPublicChainlinkToken();
    oraclePayment = _oraclePayment;
  }
  // Additional functions here:
  
}
pragma solidity ^0.5.0;

import "@chainlink/contracts/src/v0.5/ChainlinkClient.sol";

contract AmberdataChainlink is ChainlinkClient {
  
  uint256 oraclePayment;
  
  constructor(uint256 _oraclePayment) public {
    setPublicChainlinkToken();
    oraclePayment = _oraclePayment;
  }
  // Additional functions here:
  
}
pragma solidity ^0.6.0;

import "@chainlink/contracts/src/v0.6/ChainlinkClient.sol";

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

Tasks

Bool Job:

Bytes32 Job:

Int256 Job:

Uint256 Job:

Raw Bytes Job:

Request Parameters

extPath

Required

Appends the path to select the endpoint of the API to call.

Solidity example

req.add("extPath", "transactions/gas/predictions");

queryParams

Optional depending on the endpoint.

The query parameters to append to the API's URL.

Solidity example

req.add("queryParams", "status=all&size=1");

path

Required

The path of the response to parse.

Solidity example

req.add("path", "payload.average.gasPrice");

times

Optional with uint256 job.

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

Solidity example

req.addInt("times", 100);

Chainlink Examples

The examples below show how to create a request for the Chainlink node. Using Amberdata's API documentation, it's easy to see how to create requests for any supported endpoint.

function requestGasPrice(address _oracle, bytes32 _jobId) public onlyOwner {
  Chainlink.Request memory req = buildChainlinkRequest(_jobId, address(this), this.fulfillGasPrice.selector);
  req.add("extPath", "transactions/gas/predictions");
  req.add("path", "payload.average.gasPrice");
  sendChainlinkRequestTo(_oracle, req, oraclePayment);
}
function requestTokenPrice(address _oracle, bytes32 _jobId, string _tokenAddress) public onlyOwner {
  Chainlink.Request memory req = buildChainlinkRequest(_jobId, address(this), this.fulfillTokenPrice.selector);
  req.add("extPath", concat("market/tokens/prices/", _tokenAddress, "/latest"));
  req.add("path", "payload.0.priceUSD");
  req.addInt("times", 100);
  sendChainlinkRequestTo(_oracle, req, oraclePayment);
}

function concat(string a, string b, string c) private pure returns (string) {
  return string(abi.encodePacked(a, b, c));
}

Here is an example of the fulfill method:

uint256 public currentGasPrice;

function fulfillGasPrice(bytes32 _requestId, uint256 _gasPrice)
  public
  recordChainlinkFulfillment(_requestId)
{
  currentGasPrice = _gasPrice;
}
uint256 public currentTokenPrice;

function fulfillTokenPrice(bytes32 _requestId, uint256 _price)
  public
  recordChainlinkFulfillment(_requestId)
{
  currentTokenPrice = _price;
}

Chainlink Job (Node Operator)

As a node operator, you can add the following jobs to your node and be able to provide this data without an external adapter. Replace YOUR_API_KEY with your Amberdata API key.

{
    "initiators": [
        {
            "type": "runlog"
        }
    ],
    "tasks": [
        {
            "type": "httpget",
            "params": {
                "get": "https://web3api.io/api/v1/",
                "headers": {
                    "x-api-key": [
                        "YOUR_API_KEY"
                    ]
                }
            }
        },
        {
            "type": "jsonparse"
        },
        {
            "type": "ethbool"
        },
        {
            "type": "ethtx"
        }
    ]
}
{
    "initiators": [
        {
            "type": "runlog"
        }
    ],
    "tasks": [
        {
            "type": "httpget",
            "params": {
                "get": "https://web3api.io/api/v1/",
                "headers": {
                    "x-api-key": [
                        "YOUR_API_KEY"
                    ]
                }
            }
        },
        {
            "type": "jsonparse"
        },
        {
            "type": "ethbytes32"
        },
        {
            "type": "ethtx"
        }
    ]
}
{
    "initiators": [
        {
            "type": "runlog"
        }
    ],
    "tasks": [
        {
            "type": "httpget",
            "params": {
                "get": "https://web3api.io/api/v1/",
                "headers": {
                    "x-api-key": [
                        "YOUR_API_KEY"
                    ]
                }
            }
        },
        {
            "type": "jsonparse"
        },
        {
            "type": "multiply"
        },
        {
            "type": "ethint256"
        },
        {
            "type": "ethtx"
        }
    ]
}
{
    "initiators": [
        {
            "type": "runlog"
        }
    ],
    "tasks": [
        {
            "type": "httpget",
            "params": {
                "get": "https://web3api.io/api/v1/",
                "headers": {
                    "x-api-key": [
                        "YOUR_API_KEY"
                    ]
                }
            }
        },
        {
            "type": "jsonparse"
        },
        {
            "type": "multiply"
        },
        {
            "type": "ethuint256"
        },
        {
            "type": "ethtx"
        }
    ]
}
{
    "initiators": [
        {
            "type": "runlog"
        }
    ],
    "tasks": [
        {
            "type": "httpget",
            "params": {
                "get": "https://web3api.io/api/v1/",
                "headers": {
                    "x-api-key": [
                        "YOUR_API_KEY"
                    ]
                }
            }
        },
        {
            "type": "jsonparse"
        },
        {
            "type": "ethtx"
        }
    ]
}

Updated 6 days ago

Amberdata 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.