-
Notifications
You must be signed in to change notification settings - Fork 499
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from smartcontractkit/harry/add-tasks-back
added tasks back in to starter kit
- Loading branch information
Showing
10 changed files
with
133 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = {} |