smartcontractkit/hardhat-starter-kit

smartcontractkit/hardhat-starter-kit — dự án frontend — đang có 1.3k sao GitHub trong nhóm Frontend. A repo for boilerplate code for testing, deploying, and shipping chainlink solidity code.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
Snapshot
Cộng tác viên hàng đầu
Xem cộng tác viên hàng đầu
[!IMPORTANT] This branch contains the Hardhat 2 starter kit. For Hardhat 3, see the hardhat-3 branch. This branch uses Solidity Remapping and the hardhat-preprocessor plugin to resolve imports correctly. If you have errors when compiling dependencies please consult the Remapping section of this README.
Tip
Please be attention that Chainlink Any API is removed from this starter kit because Chainlink Any API is currently replaced by Chainlink Functions. Please find the starter kit for Chainlink Functions here
- Chainlink Hardhat Starter Kit
- Getting Started
- Requirements
- Quickstart
- Typescript
- Usage
- Deploying Contracts
- Run a Local Network
- Using a Testnet or Live Network (like Mainnet or Polygon)
- Sepolia Ethereum Testnet Setup
- Forking
- Test
- Interacting with Deployed Contracts
- Chainlink Price Feeds
- VRF Get a random number
- Automation
- Verify on Etherscan
- Linting
- Code Formatting
- Estimating Gas
- Code Coverage
- Fuzzing
- Import Remapping
- Contributing
- Thank You!
- Resources
Chainlink Hardhat Starter Kit
Implementation of the following 3 Chainlink features using the Hardhat development environment:
- Chainlink Price Feeds
- Chainlink VRF
- Chainlink Automation
For Chainlink Functions please go to these starter kits: Hardhat | Foundry (coming soon)
For Chainlink CCIP (Cross Chain Interoperability Prototocol) please go to these starter kits: Hardhat | Foundry
Getting Started
It's recommended that you've gone through the hardhat getting started documentation before proceeding here.
Requirements
- git
- You'll know you did it right if you can run
git --versionand see a response likegit version x.x.x
- You'll know you did it right if you can run
- Nodejs
- You'll know you've installed nodejs right if you can run:
node --versionand get an output like:vx.x.x
- You'll know you've installed nodejs right if you can run:
- Yarn instead of
npm- You'll know you've installed yarn right if you can run:
yarn --versionAnd get an output like:x.x.x- You might need to install it with npm
- You'll know you've installed yarn right if you can run:
If you're familiar with
npxandnpminstead ofyarn, you can usenpxfor execution andnpmfor installing dependencies.
Quickstart
- Clone and install dependencies
After installing all the requirements, run the following:
git clone https://github.com/smartcontractkit/hardhat-starter-kit/
cd hardhat-starter-kit
Then:
npm install
The recommendation is to use npm 7 or later. If you are using an older version of npm, you'll also need to install all the packages used by the toolbox.
npm install --save-dev @nomicfoundation/hardhat-toolbox @nomicfoundation/hardhat-network-helpers @nomicfoundation/hardhat-chai-matchers @nomiclabs/hardhat-ethers @nomiclabs/hardhat-etherscan chai ethers hardhat-gas-reporter solidity-coverage @typechain/hardhat typechain @typechain/ethers-v5 @ethersproject/abi @ethersproject/providers
That's also the case if you are using yarn.
yarn add --dev @nomicfoundation/hardhat-toolbox @nomicfoundation/hardhat-network-helpers @nomicfoundation/hardhat-chai-matchers @nomiclabs/hardhat-ethers @nomiclabs/hardhat-etherscan chai ethers hardhat-gas-reporter solidity-coverage @typechain/hardhat typechain @typechain/ethers-v5 @ethersproject/abi @ethersproject/providers
- You can now do stuff!
npx hardhat test
or
npm run test
or
yarn test
Typescript
To use typescript, run:
git checkout typescript
npm install
Usage
If you run npx hardhat --help you'll get an output of all the tasks you can run.
Deploying Contracts
npm run deploy
This will deploy your contracts to a local network. Additionally, if on a local network, it will deploy mock Chainlink contracts for you to interact with. If you'd like to interact with your deployed contracts, skip down to Interacting with Deployed Contracts.
Run a Local Network
One of the best ways to test and interact with smart contracts is by using a local network. To run a local network with all your contracts in it, execute the following command:
npx hardhat node
You'll get a local blockchain, private keys, contracts deployed (from the deployment folder scripts), and an endpoint to potentially add to an EVM wallet.
Using a Testnet or Live Network (like Mainnet or Polygon)
In your hardhat.config.js you'll see section like:
module.exports = {
defaultNetwork: "hardhat",
networks: {
This section of the file is where you define which networks you want to interact with. You can read more about that whole file in the hardhat documentation.
To interact with a live or test network, you'll need:
- An rpc URL
- A Private Key
- ETH & LINK token (either testnet or real)
Let's look at an example of setting these up using the Sepolia testnet.
Sepolia Ethereum Testnet Setup
First, we will need to set environment variables. We can do so by setting them in our .env file (create it if it's not there). You can also read more about environment variables from the linked twilio blog. You'll find a sample of what this file will look like in .env.example
IMPORTANT: MAKE SURE YOU'D DON'T EXPOSE THE KEYS YOU PUT IN THIS
.envFILE. By that, I mean don't push them to a public repo, and please try to keep them keys you use in development not associated with any real funds.
- Set your
SEPOLIA_RPC_URLenvironment variable.
You can get one for free from Alchemy, Infura, or Moralis. This is your connection to the blockchain.
- Set your
PRIVATE_KEYenvironment variable.
This 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.
⚠️ WARNING ⚠️
When developing, it's best practice to use a Metamask that isn't associated with any real money. A good way to do this is to make a new browser profile (on Chrome, Brave, Firefox, etc) and install Metamask on that browser, and never send this wallet money.
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:
SEPOLIA_RPC_URL='https://sepolia.infura.io/v3/asdfadsfafdadf'
PRIVATE_KEY='abcdef'
bash example:
export SEPOLIA_RPC_URL='https://sepolia.infura.io/v3/asdfadsfafdadf'
export PRIVATE_KEY='abcdef'
You can also use a
MNEMONICinstead of aPRIVATE_KEYenvironment variable by uncommenting the section in thehardhat.config.js, and commenting out thePRIVATE_KEYline. However this is not recommended.
For other networks like mainnet and polygon, you can use different environment variables for your RPC URL and your private key. See the hardhat.config.js to learn more.
- Get some Sepolia Testnet ETH and LINK
Head over to the Chainlink faucets and get some ETH and LINK. Please follow the chainlink documentation if unfamiliar.
- Create VRF V2 subscription
Head over to VRF Subscription Page and create the new subscription. Save your subscription ID and put it in helper-hardhat-config.js file as subscriptionId
- Running commands
You should now be all setup! You can run any command and just pass the --network sepolia now!
To deploy contracts:
npm run deploy --network sepolia
To run staging testnet tests
npm run test-staging
Forking
If you would like to run tests on a forked network, follow these steps:
- Set a
MAINNET_RPC_URLenvironment variable that connects to the mainnet. - Choose a block number to select a state of the network you are forking and set it as
FORKING_BLOCK_NUMBERenvironment variable. If ignored, it will use the latest block each time which can lead to test inconsistency. - Set
enabledflag totrue/falseto enable/disable forking feature
forking: {
url: MAINNET_RPC_URL,
blockNumber: FORKING_BLOCK_NUMBER,
enabled: false,
}
Test
Tests are located in the test directory, and are split between unit tests and staging/testnet tests. Unit tests should only be run on local environments, and staging tests should only run on live environments.
To run unit tests:
npx hardhat test
or
npm run test
or
yarn test
To run staging tests on Sepolia network:
npx hardhat test --network sepolia
or
npm run test-staging
Performance optimizations
Since all tests are written in a way to be independent from each other, you can save time by running them in parallel. Make sure that AUTO_FUND=false inside .env file. There are some limitations with parallel testing, read more about them here
To run tests in parallel:
npx hardhat test --parallel
or
npm run test --parallel
Interacting with Deployed Contracts
After deploying your contracts, 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
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. As explained in the developer documentation, there are two methods:
- The Subscription method
- The Direct Funding method
Read the docs first to understand which method is the most suitable for your use case.
VRF Subscription method
To start, go to VRF Subscription Page and create the new subscription. Save your subscription ID and put it in helper-hardhat-config.js file as subscriptionId:
5: {
// rest of the config
subscriptionId: "777"
}
Then, deploy your VRF V2 contract consumer to the network of your recent subscription using subscription id as constructor argument.
npm run deploy --network network
Finally, you need to go to your subscription page one more time and add the address of deployed contract as a new consumer. Once that's done, 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
VRF Direct Funding method
Deploy your VRF V2 contract consumer to the network.
npm run deploy --network network
or (if you are using yarn)
yarn deploy --network network
Now you have to fund your consumer contract with LINK tokens:
npx hardhat transfer-link --recipient insert-contract-address-here --amount insert-amount-in-juels-here --network network
Once that's done, you can perform a VRF request with the request-random-number task:
npx hardhat request-random-number-direct-funding --callbackgaslimit insert-callback-gas-limit-here --requestconfirmations insert-request-confirmations-here --numwords insert-number-words-here --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-direct-funding --contract insert-contract-address-here --network network
Automation
The AutomationCounter contract is a simple Chainlink Automation enabled contract that simply maintains a counter variable that gets incremented each time the performUpkeep task is performed by a Chainlink Automation. Once the contract is deployed, you should head to https://automation.chain.link/ to register it for upkeeps, then you can use the task below to view the counter variable that gets incremented by Chainlink Automation
npx hardhat read-automation-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.. If you have it set, your deploy script will try to verify them by default, but if you want to verify any manually, you can run:
npx hardhat verify --network <NETWORK> <CONTRACT_ADDRESS> <CONSTRUCTOR_PARAMETERS>
example:
npx hardhat verify --network sepolia 0x9279791897f112a41FfDa267ff7DbBC46b96c296 "0x694AA1769357215DE4FAC081bf1f309aDC325306"
Linting
This will lint your smart contracts.
npm run lint:fix
Code Formatting
This will format both your javascript and solidity to look nicer.
npm run format
Estimating Gas
To estimate gas, just set a REPORT_GAS environment variable to true, and then run:
npx hardhat test
If you'd like to see the gas prices in USD or other currency, add a COINMARKETCAP_API_KEY from Coinmarketcap.
Code coverage
To see a measure in percent of the degree to which the smart contract source code is executed when a particular test suite is run, type
npm run coverage
Fuzzing
We are going to use Echidna as a Fuzz testing tool. You need to have Docker installed with at least 8GB virtual memory allocated (To update this parameter go to Settings->Resources->Advanced->Memory).
To start Echidna instance run
npm run fuzzing
If you are using it for the first time, you will need to wait for Docker to download eth-security-toolbox image for us.
To start Fuzzing run
echidna-test /src/contracts/test/fuzzing/AutomationCounterEchidnaTest.sol --contract AutomationCounterEchidnaTest --config /src/contracts/test/fuzzing/config.yaml
To exit Echidna type
exit
Import Remapping
In Solidity, remapping is a way to define shorthand import paths so that developers can avoid writing long relative paths when importing contracts. For example, instead of writing import "../../node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol";, you could define a remapping such as @openzeppelin/=node_modules/@openzeppelin/ and simply use import "@openzeppelin/contracts/token/ERC20/ERC20.sol";. This makes contract imports cleaner, easier to maintain, and more consistent across different projects. Remappings are commonly used in development environments like Foundry or Hardhat 3, but Hardhat 2 does not support them natively.
To work around this limitation, you can use the hardhat-preprocessor plugin, which preprocesses Solidity files before compilation and rewrites the imports according to your remapping rules. This plugin works by extending the available configuration options of the expected HardhatUserConfig object to include a preprocess property.
This starter kit contains example code of this workaround in action within the remappings-helper.js file, and uses the remappings located within remappings.txt.
[!WARNING] The hardhat-preprocessor plugin is a third-party plugin. Use it at your own discretion and review its source before adopting it in any production environments.
Adding your own remappings
As your project expands, you may find the need for more dependencies. This may result in the requirement of additional remappings. To include more remappings, simply add your remapping to the remappings.txt file.
The expected syntax is: <prefix>=<resolved-path>
Contributing
Contributions are always welcome! Open a PR or an issue!
Thank You!
Resources
- Chainlink Documentation
- Hardhat Documentation
Disclaimer: Please note, this repo contains community examples only — these are not Chainlink products or services and are not supported or maintained by Chainlink. This code represents an example of using a Chainlink product or service, and is intended for demonstration and educational purposes only. It is provided “AS IS” and “AS AVAILABLE” without warranties of any kind, may not have been audited, and may omit checks or error handling. Each party intending to use this example code does so entirely at their own risk and must perform its own audits, security and code review, key management, and testing before any production deployment and ensure the operation and performance of such code matches expectations. Neither Chainlink Labs nor the Chainlink Foundation deploys, operates, monitors, maintains or endorses any deployment of this code. Note that this is not a Chainlink product, feature or service, and there are no commitments made with respect to the code, including compatibility with future Chainlink releases. You should not rely on this code without first conducting your own technical, engineering, and security review. This code is also outside the scope of any Chainlink bug bounty programs. Neither Chainlink Labs, the Chainlink Foundation, nor Chainlink node operators are responsible for outcomes due to errors in this example or how it is deployed or operated, or liable for any resulting claims or damages. Use of the Chainlink Network is subject to the Chainlink Foundation Terms of Service, which provides important information and disclosures. By using this code, you acknowledge and agree to these terms.
Repo liên quan
freeCodeCamp is a free, self-paced curriculum for learning to code, published as open source at freeCodeCamp/freeCodeCamp. It's a 501(c)(3) nonprofit funded by donor support, structured around six certifications in its Full-Stack Developer Curriculum, each gated by required projects instead of open-book quizzes. The repository also carries beta language certifications for developers, interview-prep resources, and the code that runs the live freecodecamp.org platform.
What GitHub issues dated 2014-10-10 to 2025-09-26 say about Vue 2, now at End of Life, plus where the repo stands today.
Bootstrap is an open-source front-end framework maintained at twbs/bootstrap. It ships compiled and minified CSS and JavaScript for building responsive, mobile-first sites, is licensed under MIT, and the release referenced throughout the README's install instructions is v5.3.8. The project was created by Mark Otto and Jacob Thornton, and its documentation is built with Astro and hosted at getbootstrap.com.
Airbnb JavaScript Style Guide is a public reference of JavaScript coding conventions maintained in the airbnb/javascript GitHub repository, covering rules for types, references, objects, arrays, destructuring, strings, and functions, among other topics. Most guidelines cite a matching ESLint rule and show bad-versus-good code side by side, and the project also links companion guides for React and CSS-in-JavaScript.
Trả lời nhanh
Cùng nhóm Frontend còn repo nào?
smartcontractkit/hardhat-starter-kit thuộc nhóm Frontend trên TopGit, cùng 3 topic GitHub. Trang Trending và Topics liệt kê các repo cùng số sao và cùng ngôn ngữ để so sánh.
Đọc thêm về smartcontractkit/hardhat-starter-kit ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/smartcontractkit/hardhat-starter-kit là nguồn chính thức.
smartcontractkit/hardhat-starter-kit có bao nhiêu sao?
smartcontractkit/hardhat-starter-kit có 1.3k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/smartcontractkit/hardhat-starter-kit. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
smartcontractkit/hardhat-starter-kit có phải mã nguồn mở không?
TopGit chưa ghi nhận license cho smartcontractkit/hardhat-starter-kit. Phần lớn repo public trên GitHub là mã nguồn mở, nhưng điều khoản khác nhau từng repo — mở file LICENSE để xác nhận.
smartcontractkit/hardhat-starter-kit còn đang phát triển không?
Commit gần nhất trên smartcontractkit/hardhat-starter-kit là 10 tháng trước (theo timestamp GitHub). Repo có 509 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
smartcontractkit/hardhat-starter-kit là gì?
smartcontractkit/hardhat-starter-kit (smartcontractkit/hardhat-starter-kit) là dự án JavaScript trên GitHub. Theo mô tả gốc: A repo for boilerplate code for testing, deploying, and shipping chainlink solidity code.
smartcontractkit/hardhat-starter-kit viết bằng ngôn ngữ gì?
smartcontractkit/hardhat-starter-kit chủ yếu viết bằng JavaScript. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc đầy đủ README ở tab phía trên.
Vẫn đang phân vân về hardhat-starter-kit?
Một cú bấm sẽ gửi câu hỏi kèm trang này cho AI — xem AI nói gì về hardhat-starter-kit.