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

CryptoCompare Chainlink (Testnet)

CryptoCompare provides a free API for getting cryptocurrency live pricing data, OHLC historical data, volume data or tick data from multiple exchanges. You can also get free aggregated news and block explorer data (supply, hashrate, latest block number etc).

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: 0xc99B3D447826532722E41bc36e644ba3479E4365
JobID: 35e428271aad4506afc4f4089ce98f68

Rinkeby

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

Kovan

LINK token address: 0xa36085F69e2889c224210F603D836748e7dC0088
Oracle address: 0x2f90A6D021db21e1B2A077c5a37B3C7E75D15b7e
JobID: 7f350c947b0d4d758aadd5acb41d2474

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

  uint256 oraclePayment;

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

Tasks

Request Parameters

endpoint

Required

The endpoint of the CryptoCompare API to use.

Accepted inputs:

  • price
  • dayAvg
  • generateAvg

Solidity example

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

fsym or fsyms

Required

The symbol or symbols (comma-separated) of the cryptocurrency.

Solidity example

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

Or

req.add("fsyms", "ETH,BTC");

tsym or tsyms

Required

The symbol or symbols (comma-separated) of the market to convert the price to.

Solidity example

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

Or

req.add("tsyms", "USD,EUR,JPY");

exchange or e

The exchange to use for the generate custom average endpoint.

Solidity example

req.add("exchange", "Kraken");

Or

req.add("e", "Bitfinex");

copyPath

Required

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

Returned data example:

{"USD":285.66}

Solidity example

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

times

Required

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 requests for different endpoints supported by this Chainlink.

function requestCryptoComparePrice
(
  address _oracle,
  bytes32 _jobId,
  string _coin,
  string _market
) 
  public
  onlyOwner
{
  Chainlink.Request memory req = buildChainlinkRequest(_jobId, this, this.fulfill.selector);
  req.add("endpoint", "price");
  req.add("fsym", _coin);
  req.add("tsyms", _market);
  req.add("copyPath", _market);
  req.addInt("times", 100);
  sendChainlinkRequestTo(_oracle, req, oraclePayment);
}
function requestCryptoCompareAverage
(
  address _oracle,
  bytes32 _jobId,
  string _coin,
  string _market
) 
  public
  onlyOwner
{
  Chainlink.Request memory req = buildChainlinkRequest(_jobId, this, this.fulfill.selector);
  req.add("endpoint", "dayAvg");
  req.add("fsym", _coin);
  req.add("tsym", _market);
  req.add("copyPath", _market);
  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 CryptoCompare's coinlist API endpoint.

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