1. Home
  2. Docs
  3. SmartContracts
  4. SmartContracts Tutorials
  5. Create a Chainlinked Project

Create a Chainlinked Project

Once you’ve determined that you want to use the Chainlink Library to create a ChainlinkClient contract, you can then proceed to creating a new Chainlink project or updating an existing one. In this section, we’ll explain everything you need to know on how to do so.

Creating a new Chainlinked project

Using Truffle, it’s very easy to get started creating Chainlinked contracts from a template. Simply run the command below to unbox a Chainlinked contract in your current directory.

truffle unbox smartcontractkit/chainlinked

truffle unbox smartcontractkit/chainlinked

Add Chainlink to your existing project

If you already have a project started, you can add Chainlink to it by running one of the following commands.

With NPM:

npm install chainlink –save

npm install chainlink --save

With Yarn:

yarn add chainlink

yarn add chainlink

If you are using ZeppelinOS, you can link it to your project by running:

zos link chainlink

zos link chainlink

Create your Chainlinked contract

Import ChainlinkClient.sol into your contract so you can inherit the behavior to create Chainlink requests. Our contracts are written for version 0.4.24 of the Solidity compiler and later.

pragma solidity ^0.4.24;

import "chainlink/contracts/ChainlinkClient.sol";

// MyContract inherits the Chainlinked contract to gain the
// functionality of creating Chainlink requests.
contract MyContract is ChainlinkClient {
  constructor(address _link) public {
    // Set the address for the LINK token for the network.
    if(_link == address(0)) {
      // Useful for deploying to public networks.
      setPublicChainlinkToken();
    } else {
      // Useful if you're deploying to a local network.
      setChainlinkToken(_link);
    }
  }
  // Additional functions here:
  
}
Was this article helpful to you? Yes No

How can we help?

Leave a Reply

Your email address will not be published. Required fields are marked *