Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added tasks back in to starter kit #36

Merged
merged 4 commits into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ require("@nomiclabs/hardhat-waffle")
require("@nomiclabs/hardhat-ethers")
require("@nomiclabs/hardhat-truffle5")
require("@nomiclabs/hardhat-etherscan")
require("@appliedblockchain/chainlink-plugins-api-consumer")
require("@appliedblockchain/chainlink-plugins-price-consumer")
require("@appliedblockchain/chainlink-plugins-random-number-consumer")
require("@appliedblockchain/chainlink-plugins-fund-link")
pappas999 marked this conversation as resolved.
Show resolved Hide resolved
require("hardhat-deploy")
require("./tasks/accounts")
require("./tasks/balance")
require("./tasks/withdraw-link")
require("./tasks/block-number")
require("./tasks/price-consumer")

require("./tasks/random-number-consumer")
require("./tasks/price-consumer")
require("./tasks/api-consumer")
require("@appliedblockchain/chainlink-plugins-fund-link")

require('dotenv').config()

Expand All @@ -42,10 +41,10 @@ module.exports = {
},
kovan: {
url: KOVAN_RPC_URL,
// accounts: [PRIVATE_KEY],
accounts: {
mnemonic: MNEMONIC,
},
accounts: [PRIVATE_KEY],
//accounts: {
// mnemonic: MNEMONIC,
// },
saveDeployments: true,
},
rinkeby: {
Expand Down
2 changes: 2 additions & 0 deletions tasks/api-consumer/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
exports.readData = require("./read-data.js")
exports.requestData = require("./request-data.js")
26 changes: 26 additions & 0 deletions tasks/api-consumer/read-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
task("read-data", "Calls an API Consumer Contract to read data obtained from an external API")
.addParam("contract", "The address of the API Consumer contract that you want to call")
.setAction(async taskArgs => {

const contractAddr = taskArgs.contract
const networkId = network.name
console.log("Reading data from API Consumer contract ", contractAddr, " on network ", networkId)
const APIConsumer = await ethers.getContractFactory("APIConsumer")

//Get signer information
const accounts = await ethers.getSigners()
const signer = accounts[0]

//Create connection to API Consumer Contract and call the createRequestTo function
const apiConsumerContract = new ethers.Contract(contractAddr, APIConsumer.interface, signer)
let result = BigInt(await apiConsumerContract.volume()).toString()
console.log('Data is: ', result)
if (result == 0 && ['hardhat', 'localhost', 'ganache'].indexOf(network.name) == 0) {
console.log("You'll either need to wait another minute, or fix something!")
}
if (['hardhat', 'localhost', 'ganache'].indexOf(network.name) >= 0) {
console.log("You'll have to manually update the value since you're on a local chain!")
}
})

module.exports = {}
23 changes: 23 additions & 0 deletions tasks/api-consumer/request-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
let { networkConfig, getNetworkIdFromName } = require('../../helper-hardhat-config')

task("request-data", "Calls an API Consumer Contract to request external data")
.addParam("contract", "The address of the API Consumer contract that you want to call")
.setAction(async taskArgs => {

const contractAddr = taskArgs.contract
let networkId = await getNetworkIdFromName(network.name)
console.log("Calling API Consumer contract ", contractAddr, " on network ", network.name)
const APIConsumer = await ethers.getContractFactory("APIConsumer")

//Get signer information
const accounts = await ethers.getSigners()
const signer = accounts[0]

//Create connection to API Consumer Contract and call the createRequestTo function
const apiConsumerContract = new ethers.Contract(contractAddr, APIConsumer.interface, signer)
var result = await apiConsumerContract.requestVolumeData()
console.log('Contract ', contractAddr, ' external data request successfully called. Transaction Hash: ', result.hash)
console.log("Run the following to read the returned result:")
console.log("npx hardhat read-data --contract " + contractAddr + " --network " + network.name)
})
module.exports = {}
1 change: 1 addition & 0 deletions tasks/price-consumer/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
exports.readPriceFeedEns = require("./read-price-feed-ens.js")
exports.readPriceFeed = require("./read-price-feed.js")
PatrickAlphaC marked this conversation as resolved.
Show resolved Hide resolved
20 changes: 20 additions & 0 deletions tasks/price-consumer/read-price-feed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
task("read-price-feed", "Gets the latest price from a Chainlink Price Feed")
.addParam("contract", "The address of the Price Feed consumer contract that you want to read")
.setAction(async taskArgs => {

const contractAddr = taskArgs.contract
const networkId = network.name

const PriceFeedConsumerContract = await ethers.getContractFactory("PriceConsumerV3")
console.log("Reading data from Price Feed consumer contract ", contractAddr, " on network ", networkId)

//Get signer information
const accounts = await ethers.getSigners()
const signer = accounts[0]
const priceFeedConsumerContract = await new ethers.Contract(contractAddr, PriceFeedConsumerContract.interface, signer)
await priceFeedConsumerContract.getLatestPrice().then((data) => {
console.log('Price is: ', BigInt(data).toString())
})
})

module.exports = {}
2 changes: 2 additions & 0 deletions tasks/random-number-consumer/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
exports.readRandomNumber = require("./read-random-number.js")
exports.requestRandomNumber = require("./request-random-number.js")
26 changes: 26 additions & 0 deletions tasks/random-number-consumer/read-random-number.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
task("read-random-number", "Reads the random number returned to a contract by Chainlink VRF")
.addParam("contract", "The address of the VRF contract that you want to read")
.setAction(async taskArgs => {

const contractAddr = taskArgs.contract
const networkId = network.name
console.log("Reading data from VRF contract ", contractAddr, " on network ", networkId)
const RandomNumberConsumer = await ethers.getContractFactory("RandomNumberConsumer")

//Get signer information
const accounts = await hre.ethers.getSigners()
const signer = accounts[0]

//Create connection to API Consumer Contract and call the createRequestTo function
const vrfConsumerContract = new ethers.Contract(contractAddr, RandomNumberConsumer.interface, signer)
let result = BigInt(await vrfConsumerContract.randomResult()).toString()
console.log('Random Number is: ', result)
if (result == 0 && ['hardhat', 'localhost', 'ganache'].indexOf(network.name) == 0) {
console.log("You'll either need to wait another minute, or fix something!")
}
if (['hardhat', 'localhost', 'ganache'].indexOf(network.name) >= 0) {
console.log("You'll have to manually update the value since you're on a local chain!")
}
})

module.exports = {}
22 changes: 22 additions & 0 deletions tasks/random-number-consumer/request-random-number.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
task("request-random-number", "Requests a random number for a Chainlink VRF enabled smart contract")
.addParam("contract", "The address of the API Consumer contract that you want to call")
.setAction(async taskArgs => {

const contractAddr = taskArgs.contract
const networkId = network.name
console.log("Requesting a random number using VRF consumer contract ", contractAddr, " on network ", networkId)
const RandomNumberConsumer = await ethers.getContractFactory("RandomNumberConsumer")

//Get signer information
const accounts = await hre.ethers.getSigners()
const signer = accounts[0]

//Create connection to VRF Contract and call the getRandomNumber function
const vrfConsumerContract = new ethers.Contract(contractAddr, RandomNumberConsumer.interface, signer)
var result = await vrfConsumerContract.getRandomNumber()
console.log('Contract ', contractAddr, ' random number request successfully called. Transaction Hash: ', result.hash)
console.log("Run the following to read the returned random number:")
console.log("npx hardhat read-random-number --contract " + contractAddr + " --network " + network.name)
})

module.exports = {}