Getting started with Chainlink development using Truffle and Infura
28 Jun 2021Chainlink
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
Hands on: Truffle + Chainlink
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.
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
- Setup Metamask and connect to Kovan network
- Faucet: faucet.kovan.network
- Create account and a project using Infura.io β step-by-step tutorial
- Infura setup and βenv.sampleβ file configuration
truffle migrate --network kovan --reset
Helper scripts
Scripts to interact with deployed smart contract without any frontend implementation:
- fund-contract.js
npx truffle exec scripts/fund-contract.js --network kovan
- request-data.js
npx truffle exec scripts/request-data.js --network kovan
- 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
Code a REAL WORLD dApp with Chainlink - Ethereum, Solidity, Web3.js