Getting started with Chainlink development using Truffle and Infura

Chainlink is a decentralized network of nodes that provide data and information from off-blockchain sources to on-blockchain smart contracts via oracles

Chainlink greatly expands the capabilities of smart contracts by enabling access to real-world data and off-chain computation while maintaining the security and reliability guarantees inherent to blockchain technology.

This tutorial will be based on this repo and we will use Truffle – a development environment, testing framework and asset pipeline for Ethereum

Prerequisite

1. Install NodeJS
2. Install Truffle: npm install -g truffle
3. Install Metamask
4. Install Ganache
5. Install VSCode
6. Install Solidity Plugin

npm install --global yarn

mkdir Chainlink

cd Chainlink

truffle unbox smartcontractkit/box

yarn

Running tests Run Ganache or enable/integrate Kovan testnet npm test

All tests of /test will be executed. There are tests about creating requests with and without Link tokens, sending these requests to oracle contract addresses, and testing contract ownership.

Kovan npm tests chainlink

Note You must acquire some LINK for interact with you smart contract. Get some LINK via Chainlink Kovan Faucet website πŸ€‘ πŸ€‘ πŸ€‘

Ganache deployment

truffle migrate --network ganache --reset

Kovan deployment

  1. Setup Metamask and connect to Kovan network
  2. Faucet: faucet.kovan.network
  3. Create account and a project using Infura.io – step-by-step tutorial
  4. Infura setup and β€œenv.sample” file configuration

truffle migrate --network kovan --reset

Android great again

Helper scripts

Scripts to interact with deployed smart contract without any frontend implementation:

  1. fund-contract.js

npx truffle exec scripts/fund-contract.js --network kovan

  1. request-data.js

npx truffle exec scripts/request-data.js --network kovan

  1. read-contract.js

npx truffle exec scripts/read-contract.js --network kovan

● fund-contract.js

➒ Send 1 LINK to requesting contract

● request-data.js

➒ Chainlink request to be created from the requesting contract

● read-contract.js

➒ Read the data variable of the requesting contract (current price of pair ETH/USD)

Additional Information

Chainlink docs

Chainlink official website

Truffle Starter kit impl

Code a REAL WORLD dApp with Chainlink - Ethereum, Solidity, Web3.js

What Is Chainlink in 5 Minutes