Using Hardhat
Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software.

Setting up Hardhat

Once your environment is ready, we can create an empty folder and init a Hardhat project in it.
1
$ mkdir my-thundercore-project && cd $_
2
3
# We choose a basic sample project and install its dependences here:
4
$ npx hardhat init
5
6
✔ What do you want to do? · Create a basic sample project
7
8
✔ Do you want to install this sample project's dependencies with npm (hardhat @nomiclabs/hardhat-waffle ethereum-waffle chai @nomiclabs/hardhat-ethers ethers)? (Y/n) · y
Copied!
After initialization, we can test the project with the hardhat compile command:
npm
Yarn
1
$ npm exec -- hardhat compile
2
Downloading compiler 0.8.4
3
Compiling 2 files with 0.8.4
4
Compilation finished successfully
Copied!
1
$ yarn hardhat compile
2
Compiling 2 files with 0.8.4
3
Compilation finished successfully
4
Done in 1.22s.
Copied!

Hardhat Config

Now, we have to add ThunderCore networks into Hardhat config file. Open and edit hatdhat.config.js in the root directory of your project.
hardhat.config.js
1
module.exports = {
2
+ networks: {
3
+ 'thunder-testnet': {
4
+ url: 'https://testnet-rpc.thundercore.com',
5
+ chainId: 18,
6
+ gas: 90000000,
7
+ gasPrice: 1e9,
8
+ accounts: process.env.KEY ? [process.env.KEY] : [],
9
+ },
10
+ 'thunder-mainnet': {
11
+ url: 'https://mainnet-rpc.thundercore.com',
12
+ chainId: 108,
13
+ gas: 90000000,
14
+ gasPrice: 1e9,
15
+ accounts: process.env.KEY ? [process.env.KEY] : [],
16
+ },
17
+ },
18
}
Copied!
Never store your private key directly in hardhat.config.js

Deploy to ThunderCore Network

Let's deploy the first contract.
You'll need some gas tokens to deploy contracts. To test on ThunderCore testnet, you can get some testnet tokens from ThunderCore testnet Faucet
Unix-like system
Windows CMD
Windows Powershell
1
# Using NPM
2
KEY=0xPrivateKey npm exec -- hardhat run scripts/sample-script.js --network thunder-testnet
3
# or using Yarn
4
KEY=0xPrivateKey yarn hardhat run scripts/sample-script.js --network thunder-testnet
Copied!
1
# Using NPM
2
set KEY=0xPrivateKey & npm exec -- hardhat run scripts/sample-script.js --network thunder-testnet
3
# or using Yarn
4
set KEY=0xPrivateKey & yarn hardhat run scripts/sample-script.js --network thunder-testnet
Copied!
1
# Using NPM
2
$env:KEY='0xPrivateKey';npm exec -- hardhat run scripts/sample-script.js --network thunder-testnet
3
# or using Yarn
4
$env:KEY='0xPrivateKey';yarn hardhat run scripts/sample-script.js --network thunder-testnet
Copied!
Congratulations! You have successfully deployed a smart contract onto the ThunderCore network, you will find the deployed messages look like:
1
Greeter deployed to: 0xGreeterContractAddress
Copied!
Copy link
Contents