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

CoinMarketCap Chainlink (Testnet)

This Chainlink supports the latest market quotes endpoint for any coin and market supported by CoinMarketCap. The CoinMarketCap Professional API is a suite of high-performance RESTful JSON endpoints that are specifically designed to meet the mission-critical demands of application developers, data scientists, and enterprise business platforms.

Steps for using this oracle

Chainlink Network Details

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

Ropsten

LINK Token address: 0x20fE562d797A42Dcb3399062AE9546cd06f63280
Oracle address: 0xc99B3D447826532722E41bc36e644ba3479E4365
JobID: ce36a79ea04c4d3ca015d267784417bd

Rinkeby

LINK token address: 0x01BE23585060835E02B77ef475b0Cc51aA1e0709
Oracle address: 0x7AFe1118Ea78C1eae84ca8feE5C65Bc76CcF879e
JobID: 0e9e244b9c374cd1a5c714caf25b0be5

Kovan

LINK token address: 0xa36085F69e2889c224210F603D836748e7dC0088
Oracle address: 0x2f90A6D021db21e1B2A077c5a37B3C7E75D15b7e
JobID: cbb45ecb040340389e49b77704184e5a

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 CoinMarketCapChainlink is ChainlinkClient {

  uint256 oraclePayment;

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

Tasks

Request Parameters

sym or cid

Required

The digital currency symbol or ID of the requested cryptocurrency. This parameter may take multiple symbols by comma separating them.

Solidity example

req.add("sym", "ETH");

or

req.add("cid", "1027");

convert

Required

The market to convert the cryptocurrency's value.

Solidity example

req.add("convert", "USD");

copyPath

Required

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

Returned data example:

{
    "status": {
        "timestamp": "2018-08-21T12:36:04.996Z",
        "error_code": 0,
        "error_message": null,
        "elapsed": 5,
        "credit_count": 1
    },
    "data": {
        "ETH": {
            "id": 1027,
            "name": "Ethereum",
            "symbol": "ETH",
            "slug": "ethereum",
            "circulating_supply": 101462385.6865,
            "total_supply": 101462385.6865,
            "max_supply": null,
            "date_added": "2015-08-07T00:00:00.000Z",
            "num_market_pairs": 3907,
            "cmc_rank": 2,
            "last_updated": "2018-08-21T12:34:43.000Z",
            "quote": {
                "USD": {
                    "price": 282.593191456,
                    "volume_24h": 1256139513.14843,
                    "percent_change_1h": -0.468603,
                    "percent_change_24h": -3.04842,
                    "percent_change_7d": 7.26957,
                    "market_cap": 28672579383.887608,
                    "last_updated": "2018-08-21T12:34:43.000Z"
                }
            }
        }
    }
}

Solidity example

string[] memory path = new string[](5);
path[0] = "data";
path[1] = "ETH";
path[2] = "quote";
path[3] = "USD";
path[4] = "price";
req.addStringArray("copyPath", path);

times

Required

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

Solidity example

req.addInt("times", 100);

Chainlink Examples

This example will give you the most recent price for the given coin on the given market.

function requestCoinMarketCapPrice
(
  address _oracle,
  bytes32 _jobId,
  string _coin,
  string _market
) 
  public
  onlyOwner
{
  Chainlink.Request memory req = buildChainlinkRequest(_jobId, this, this.fulfill.selector);
  req.add("sym", _coin);
  req.add("convert", _market);
  string[] memory path = new string[](5);
  path[0] = "data";
  path[1] = _coin;
  path[2] = "quote";
  path[3] = _market;
  path[4] = "price";
  req.addStringArray("copyPath", path);
  req.addInt("times", 100);
  sendChainlinkRequestTo(_oracle, req, oraclePayment);
}

Here is an example of the fulfill method:

uint256 public currentPrice;

function fulfill(bytes32 _requestId, uint256 _price)
  public
  recordChainlinkFulfillment(_requestId)
{
  currentPrice = _price;
}

Available Currencies

The latest coin list is available from CoinMarketCap's listings API endpoint.

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