Git Product home page Git Product logo

hackathon_chainlink's Introduction


Chainlink Hardhat logo


Chainlink Hardhat Box

Implementation of the following 3 Chainlink features using the Hardhat development environment:

Requirements

Installation

Kovan Ethereum Testnet

Set your KOVAN_RPC_URL environment variable.. You can get one for free at Infura's site. You'll also need to set the variable PRIVATE_KEY, which is your private key from your wallet, ie MetaMask. This is needed for deploying contracts to public networks. You can optionally set your MNEMONIC environment variable instead with some changes to the hardhat.config.js.

Matic Mumbai Testnet

Set your MUMBAI_RPC_URL environment variable. You can get one from the Matic docs. You'll also need to set the variable PRIVATE_KEY which is your private key from your wallet, ie MetaMask. This is needed for deploying contracts to public networks. You can obtain testnet MATIC and LINK via the MATIC Faucet

Setting Environment Variables

You can set these in your .env file if you're unfamiliar with how setting environment variables work. Check out our .env example. If you wish to use this method to set these variables, update the values in the .env.example file, and then rename it to '.env'

WARNING WARNING WARNING

Don't commit and push any changes to .env files that may contain sensitive information, such as a private key! If this information reaches a public GitHub repository, someone can use it to check if you have any Mainnet funds in that wallet address, and steal them!

.env example:

KOVAN_RPC_URL='www.infura.io/asdfadsfafdadf'
PRIVATE_KEY='abcdef'
MAINNET_RPC_URL="https://eth-mainnet.alchemyapi.io/v2/your-api-key"
MUMBAI_RPC_URL='https://rpc-mumbai.maticvigil.com'
POLYGON_MAINNET_RPC_URL='https://rpc-mainnet.maticvigil.com'

bash example

export KOVAN_RPC_URL='www.infura.io/asdfadsfafdadf'
export PRIVATE_KEY='abcdef'
export MAINNET_RPC_URL='https://eth-mainnet.alchemyapi.io/v2/your-api-key'
export MUMBAI_RPC_URL='https://rpc-mumbai.maticvigil.com'
export POLYGON_MAINNET_RPC_URL='https://rpc-mainnet.maticvigil.com'

If you plan on deploying to a local Hardhat network that's a fork of the Ethereum mainnet instead of a public test network like Kovan, you'll also need to set your MAINNET_RPC_URL environment variable. and uncomment the forking section in hardhat.config.js. You can get one for free at Alchemy's site..

You can also use a PRIVATE_KEY instead of a MNEMONIC environment variable by uncommenting the section in the hardhat.config.js, and commenting out the MNEMONIC line.

Then you can install all the dependencies

git clone https://github.com/smartcontractkit/hardhat-starter-kit/
cd hardhat-starter-kit

then

npm install

Or

yarn

Auto-Funding

This Starter Kit is configured by default to attempt to auto-fund any newly deployed contract that uses Any-API or Chainlink VRF, to save having to manually fund them after each deployment. The amount in LINK to send as part of this process can be modified in the Starter Kit Config, and are configurable per network.

Parameter Description Default Value
fundAmount Amount of LINK to transfer when funding contracts 1 LINK

If you wish to deploy the smart contracts without performing the auto-funding, run the following command when doing your deployment:

npx hardhat deploy --tags main

Deploy

Deployment scripts are in the deploy directory. If required, edit the desired environment specific variables or constructor parameters in each script, then run the hardhat deployment plugin as follows. If no network is specified, it will default to the Kovan network.

This will deploy to a local hardhat network

This will deploy to a local hardhat network

npx hardhat deploy

To deploy to testnet:

npx hardhat deploy --network kovan

Test

Tests are located in the test directory, and are split between unit tests and integration tests. Unit tests should only be run on local environments, and integration tests should only run on live environments.

To run unit tests:

yarn test

To run integration tests:

yarn test-integration

Run

The deployment output will give you the contract addresses as they are deployed. You can then use these contract addresses in conjunction with Hardhat tasks to perform operations on each contract

Chainlink Price Feeds

The Price Feeds consumer contract has one task, to read the latest price of a specified price feed contract

npx hardhat read-price-feed --contract insert-contract-address-here --network network

Request & Receive Data

The APIConsumer contract has two tasks, one to request external data based on a set of parameters, and one to check to see what the result of the data request is. This contract needs to be funded with link first:

npx hardhat fund-link --contract insert-contract-address-here --network network

Once it's funded, you can request external data by passing in a number of parameters to the request-data task. The contract parameter is mandatory, the rest are optional

npx hardhat request-data --contract insert-contract-address-here --network network

Once you have successfully made a request for external data, you can see the result via the read-data task

npx hardhat read-data --contract insert-contract-address-here --network network

VRF Get a random number

The VRFConsumer contract has two tasks, one to request a random number, and one to read the result of the random number request. This contract needs to be funded with link first:

npx hardhat fund-link --contract insert-contract-address-here --network network

Once it's funded, you can perform a VRF request with the request-random-number task:

npx hardhat request-random-number --contract insert-contract-address-here --network network

Once you have successfully made a request for a random number, you can see the result via the read-random-number task:

npx hardhat read-random-number --contract insert-contract-address-here --network network

Keepers

The KeepersCounter contract is a simple Chainlink Keepers enabled contract that simply maintains a counter variable that gets incremented each time the performUpkeep task is performed by a Chainlink Keeper. Once the contract is deployed, you should head to https://keepers.chain.link/ to register it for upkeeps, then you can use the task below to view the counter variable that gets incremeneted by Chainlink Keepers

npx hardhat read-keepers-counter --contract insert-contract-address-here --network network

Verify on Etherscan

You'll need an ETHERSCAN_API_KEY environment variable. You can get one from the Etherscan API site.

npx hardhat verify --network <NETWORK> <CONTRACT_ADDRESS> <CONSTRUCTOR_PARAMETERS>

example:

npx hardhat verify --network kovan 0x9279791897f112a41FfDa267ff7DbBC46b96c296 "0x9326BFA02ADD2366b30bacB125260Af641031331"

Linting

yarn lint:fix

hackathon_chainlink's People

Contributors

thedarkknight197 avatar

Watchers

 avatar Leonardo Gasparini avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.