smartcontractkit / hardhat-starter-kit Goto Github PK
View Code? Open in Web Editor NEWA repo for boilerplate code for testing, deploying, and shipping chainlink solidity code.
License: MIT License
A repo for boilerplate code for testing, deploying, and shipping chainlink solidity code.
License: MIT License
We should mock the callBackWithRandomness
and finish out the testing, and also for API calls.
If you run npx hardhat
for a new repo, they have a new option called Create an advanced sample project
. We should set this repo up to match their syntax.
tasks should use deployments as well
maybe include a sample script of non-deployed smart contracts
ethers.getcontractat()
We should use ethers in this starter kit and not web3
Maybe we should do one?
What are people's thoughts? Something similar to https://github.com/PatrickAlphaC/decentralized-raffle perhaps?
Hi there. I was wondering if you would consider switching to a public domain licence like CC0 or the unlicense?
Complying with the MIT licence is often not too hard - if you're using a library then you have an exact copy and you simply preserve the licence declaration. Easy. Not so when creating a derivative work, and this is a template project so all usage is derivative in nature. How do you refer to the code that remains copied from here to attribute the MIT licence?
If a part of that project itself is used to create another derivative work, how is that author to know if they have used any of this project's code, and whether they are subject to its MIT licence? That downstream author, if paying attention to compliance, may be forced to write something like:
Though I am not aware of any specific examples, there may be portions of this
project that are considered derivative of hardhat-starter-kit. The copyright
for those portions would be held by pappas999 (c) 2021, and the MIT licence
below would apply.
(MIT licence goes here)
IANAL, but to the best of my knowledge, project authors are required to do this kind of thing. I think it's a bit silly, and it would be better if we all stopped worrying about attribution in open source licences, and just committed the work to the public domain (assuming having other projects benefit from your work is the goal, of course).
Wdyt?
Add Chainlink keepers Counter contract, deploy script, new tasks and test scripts to the hardhat starter kit
yarn lint:fix
is currently broken
I think you should add the line await network.provider.send("evm_mine");
below evm_increaseTime, on the typescript keepers test file.
Or at least that's what I had to do on my local file to make the time increase have any real effect.
Reference:
https://ethereum.stackexchange.com/questions/86633/time-dependent-tests-with-hardhat
The current mocklink is... gross. Let's get a better one.
Update contracts to v0.8 of Solidity
We want to do hardhat deploy first, with deployments.fixture
await deployments.fixture()
await deployments.get()
This makes the deployments run once, before every test.
https://www.npmjs.com/package/hardhat-deploy#creating-fixtures
As per the comments in #58
Integration tests should listen for the emitted event from the fulfilling call instead of a general wait/sleep before checking the result of the API call or VRF request
Speaking with jb, he was running into errors because he was confused why he couldn't do anything.
The readme is unclear about which networks things are running on.
In addition to the standard GET request for Chainlink Connect to any API, Chainlink also supports multi-variable and large (bytes or string > 32bytes) responses.
On first glance it appears that executing these examples in hardhat-starter-kit will require a adjustment to, or the addition of a second MockOracle.
npx hardhat request-random-number --contract
shouldn't be a plug-in. It abstracts how this task is happening and isn't something a lot of projects are necessarily going to use. We want to show users how to make this task.
Please add this task back in.
In fact, the majority of these shouldn't be abstracted out. The only tasks that should be tasks are reading price feeds and funding LINK .
Since VRF Subscription will be different chain to chain, it shouldn't be an environment variable, instead, in the config.
This will deploy mocks IF the chainId is a developChain id, then you can just call like "getAddress" and not duplicate deploy.
Also use:
Use const LinkToken = await deployments.get('LinkToken')
in the scripts
within the deploy directory, and this will clean up the test output
const { deploy } = deployments
Change to
const { deploy, log } = deployments
The readme still calls this a Box instead of a starter kit. Can we fix this?
cc: @andrejrakic
To the Chainlink devrel node
kovan:
oracle: '0xc57b33452b4f7bb189bb5afae9cc4aba1f7a4fd8'
jobId: 'd5270d1c311941d0b08bead21fea7747'
rinkeby:
oracle: '0xc57b33452b4f7bb189bb5afae9cc4aba1f7a4fd8'
jobId: '6b88e0402e5d415eb946e528b8e0c7ba'
The requestId from
const transaction = await randomNumberConsumer.getRandomNumber()
const transactionReceipt = await transaction.wait(1)
const requestId = transactionReceipt.events[0].topics[1]
is different to the requestId from the RandomNumberConsumer contract if you log and see them
function getRandomNumber() public returns (bytes32 requestId) {
require(LINK.balanceOf(address(this)) >= fee, "Not enough LINK - fill contract with faucet");
requestId = requestRandomness(keyHash, fee);
console.logBytes32(requestId);
}
hey @PatrickAlphaC I have a doubt about line 100, it is calling the RandomNumberConsumer but I should assign the V2 at the end of the name, please correct me if I am wrong.
We don't need to do this. We should just encode the jobid using ethers.
This is best practice anyways.
immutable
variables save on gas, and cannot be changed and we have a number of variables that we won't want to change, like the VRFCoordinator address.
We can also use immutable
to set these variables in the constructor.
constant
variables cannot be set in the constructor.
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@appliedblockchain/chainlink-plugins-fund-link/-/chainlink-plugins-fund-link-0.0.1.tgz
npm ERR! 404
npm ERR! 404 '@appliedblockchain/[email protected]' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404 It was specified as a dependency of 'hardhat-starter-kit'
error An unexpected error occurred: "https://registry.yarnpkg.com/@appliedblockchain%2fchainlink-plugins-fund-link: Not found".
use named accounts instead of that garbaged "if network is kovan -> do this, if network is rinkeby -> do this"
We need to test that the random number is returned by calling callBackWithRandomness
in our VRF unit tests.
the hardhat runtime environment is perfect for testing and doing everything we need to do.
Would it be possible to have the fulfillRandomness
fire from the mock during tests, so that the following behaviour can be tested in unit-tests? This does not seem to happen in my project. It does not in your starter either.
The contract I would like to create really depends on this random value as its starting point, without alternative public entrypoints to accomodate for testing (the random value not being manipulated from outside factors is crucial when the contract is deployed on a real chain).
How are people testing this today?
have the default network be hardhat, and have it smart enough to swap addresses based on the network. Including deploying mocks if you're on a local network.
In the RandomNumberConsumerV2 unit test, the result of the number is validated with always being greater than zero.
At first it's fine. but how is it applied for the moment in which it must be tested with a winning or specific number?
assert(firstRandomNumber.gt(ethers.constants.Zero))
Is there any way to provide the number as in the v1 mock?
it("Should successfully request a random number and get a result", async () => { const transaction = await randomNumberConsumer.getRandomNumber() const transactionReceipt = await transaction.wait(1) const requestId = transactionReceipt.events[0].topics[1] const randomValue = 777 await vrfCoordinatorMock.callBackWithRandomness( requestId, randomValue, randomNumberConsumer.address ) assert.equal((await randomNumberConsumer.randomResult()).toString(), randomValue) })
Big, bold, tell users not to do it.
Right now, we deploy the VRFCoordinatorV2Mock as such:
await deploy("VRFCoordinatorV2Mock", {
from: deployer,
log: true,
args: [
POINT_ONE_LINK,
1e9, // 0.000000001 LINK per gas
],
})
POINT_ONE_LINK
and 1e9
are not descriptive for what each stands for, they should be something like:
BASE_FEE,
GAS_PRICE_LINK
Respectively, with a link explaining what each means.
The bash environment variable names (in the readme) are inconsistent with the env file. Rename PRIVATE_KEY as MNEMONIC in the env and example env files, or, add them in addition to PRIVATE_KEY.
In 00_Deploy_Mocks.js l.34 the instruction is "Please run 'npx hardhat console' to interact with the deployed smart contracts!
Should it be npx hardhat node
instead ?
hardhat-starter-kit/contracts/RandomNumberConsumer.sol
states:
/**
* THIS IS AN EXAMPLE CONTRACT WHICH USES HARDCODED VALUES FOR CLARITY.
* PLEASE DO NOT USE THIS CODE IN PRODUCTION.
*/
But it's unclear what it is referring to when it says "Hardcoded values", it doesn't look like there are any hardcoded values, and the contract appears to be fine for a production deployment aside from maybe also having a withdraw function for any LINK in the contract.
Am I missing something which makes this unsuitable for a production deployment (aside from the withdraw function)? Are there any hardcoded values here?
Link for clarity: https://github.com/smartcontractkit/hardhat-starter-kit/blob/main/contracts/RandomNumberConsumer.sol#L5-L8
First of all, thanks for putting this demo repo together.
I'm trying to test some smart contracts that interact with VRF locally. Even though I think I've followed the instructions correctly, I keep getting 0
as the randomly generated number, regardless of the seed.
Looking at the code, it seems like this line would be logging You'll either need to wait another minute, or fix something!
, but it won't do that either, since the result is being casted into a string.
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!")
}
Is there anything I could be missing?
Thanks!
Version 0.6 of the LINK token imports openzeppelin contracts, which can cause conflicts when others want to use OZ packages.
Default to the mock contract using v0.4 of solidity to avoid collision
The developer experience on mumbai is not good. I'd much rather developers use kovan, rinkeby, or other instead.
Many are running into odd unexplained errors.
I came across this repository while reading the Chainlink documentation about how to set it up with Hardhat. I gotta say you guys did an amazing job setting this up.
I see some bits of it could be extracted in separate npm packages, which could be used in existing set-ups (when someone doesn't start from this project):
If you guys think it might be a good idea, let me know. I am more than happy to help with this.
The repository could still be used as reference of the final implementation though.
Please I need help with generating a ChainLink VRFConsumerBaseV2 and testing it out on my local development
How to call the contract from frontend to generate randomness
The guide out there only covers for Chainlink V1
Sincerely appreciate your help
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.