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

Make an Existing Job Request

Using an existing Oracle Job makes your smart contract code more succinct. This page explains how to make an HTTP GET request to the ETH-USD Price endpoint in the CoinGecko API, to retrieve the price of ETH, using an existing Oracle job.

Coin Gecko Consumer

In Make a GET Request, the example contract code declared which URL to hit, where to find the data in the response, and how to convert it so that it can be represented on-chain.

In this example, an Oracle Job was found on Chainlink Market that is pre-configured to perform these tasks. This means that our contract needn't specify them itself, it only needs the Oracle address and the Job ID.

This example uses the Alpha Chain Kovan oracle, which runs the ETH-USD CoinGecko Job.

The contract should own enough LINK to pay the specified fee. The beginner walkthrough explains how to fund your contract.

pragma solidity ^0.6.0;

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

contract CoinGeckoConsumer is ChainlinkClient {
    address private oracle;
    bytes32 private jobId;
    uint256 private fee;
    
    uint256 public ethereumPrice;
    
    /**
     * Network: Kovan
     * Oracle: 
     *      Name:           AlphaChain Kovan
     *      Listing URL:    https://market.link/nodes/ef076e87-49f4-486b-9878-c4806781c7a0?start=1601380594&end=1601985394
     *      Address:        0xAA1DC356dc4B18f30C347798FD5379F3D77ABC5b
     * Job: 
     *      Name:           ETH-USD CoinGecko
     *      Listing URL:    https://market.link/jobs/78868caf-4a75-4dbf-a4cf-52538a283409
     *      ID:             9cc0c77e8e6e4f348ef5ba03c636f1f7
     *      Fee:            0.1 LINK
     */
    constructor() public {
        setPublicChainlinkToken();
        oracle = 0xAA1DC356dc4B18f30C347798FD5379F3D77ABC5b; // oracle address
        jobId = "9cc0c77e8e6e4f348ef5ba03c636f1f7"; //job id
        fee = 0.1 * 10 ** 18; // 0.1 LINK
    }
    
    /**
     * Make initial request
     */
    function requestEthereumPrice() public {
        Chainlink.Request memory req = buildChainlinkRequest(jobId, address(this), this.fulfillEthereumPrice.selector);
        sendChainlinkRequestTo(oracle, req, fee);
    }
    
    /**
     * Callback function
     */
    function fulfillEthereumPrice(bytes32 _requestId, uint256 _price) public recordChainlinkFulfillment(_requestId) {
        ethereumPrice = _price;
    }
}

For more information on finding existing jobs, see Find Existing Jobs.

Updated 21 days ago



Make an Existing Job Request


Suggested Edits are limited on API Reference Pages

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