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!

Contract Examples

Here are Chainlink contract examples that you can use to get started writing externally-connected smart contracts.

pragma solidity 0.4.24;

import "chainlink/solidity/contracts/Chainlinked.sol";

contract ChainlinkExample is Chainlinked {

  bytes32 public bytesData;
  uint256 public numberData;
  address public owner;

  constructor(address _link, address _oracle) public {
    setLinkToken(_link);
    setOracle(_oracle);
    owner = msg.sender;
  }

  function requestExternalBytesData(
    bytes32 _jobId,
    string _url,
    string _path,
    uint256 _payment
  )
    public
    onlyOwner
    returns (bytes32 requestId)
  {
    // newRequest takes a JobID, a callback address, and callback function as input
    Chainlink.Request memory req = newRequest(_jobId, this, this.fulfillBytes32.selector);
    req.add("get", _url);
    req.add("path", _path);
    requestId = chainlinkRequest(req, _payment);
  }
  
  function requestExternalNumberData(
    bytes32 _jobId,
    string _url,
    string _path,
    int256 _times,
    uint256 _payment
  )
    public
    onlyOwner
    returns (bytes32 requestId)
  {
    // newRequest takes a JobID, a callback address, and callback function as input
    Chainlink.Request memory req = newRequest(_jobId, this, this.fulfillUint256.selector);
    req.add("get", _url);
    req.add("path", _path);
    req.addInt("times", _times);
    requestId = chainlinkRequest(req, _payment);
  }

  function fulfillBytes32(bytes32 _requestId, bytes32 _data)
    public
    recordChainlinkFulfillment(_requestId)
  {
    bytesData = _data;
  }
  
  function fulfillUint256(bytes32 _requestId, uint256 _data)
    public
    recordChainlinkFulfillment(_requestId)
  {
    numberData = _data;
  }
  
  modifier onlyOwner() {
    require(msg.sender == owner);
    _;
  }
}