Skip to content

NightKids-io/nightKick-smartcontract

Repository files navigation

Hardhat Starterkit Template (JavaScript)

Inspiration - Solidity Template

This is a GitHub template, which means you can reuse it as many times as you want. You can do that by clicking the "Use this template" button at the top of the page.

Usage

Pre Requisites

Before running any command, you need to create a .env file and set all necassary environment variables. Follow the example in .env.example. You can either use mnemonic or individual private keys by setting

$ ACCOUNT_TYPE="MNEMONIC"
or
$ ACCOUNT_TYPE="PRIVATE_KEYS"

If you don't already have a mnemonic, use this website to generate one Or if you don't already have a private key, use this website to generate one.

Then, proceed with installing dependencies:

$ yarn install

Compile

Compile the smart contracts with Hardhat:

$ yarn compile

Lint Solidity

Lint the Solidity code:

$ yarn lint:sol

Test

Run the Mocha tests:

$ yarn test

Coverage

Generate the code coverage report:

$ yarn coverage

Report Gas

See the gas usage per unit test and average gas per method call:

$ REPORT_GAS=true yarn test

Optional:

  • See the actual fiat currency rates by setting your coingecko api key from here in .env file or command.

  • Set custom gas price (gwei) in .env file or command or let it automatically fetched by ethgasstationapi.

$ GAS_PRICE=20
$ COIN_MARKET_CAP_API_KEY="your_api_key"
$ yarn test

Clean

Delete the smart contract artifacts, the coverage reports and the Hardhat cache:

$ yarn clean

Deploy

Deploy the contracts to Hardhat Network:

$ yarn deploy

Deploy the contracts to a specific network, such as the Rinkeby testnet:

$ yarn deploy:network rinkeby

Manual Verify

$ npx hardhat verify --network <network> DEPLOYED_CONTRACT_ADDRESS "Constructor argument 1" "Constructor argument 2"

For complex arguments you can refer here

$ npx hardhat verify --contract contracts/CONTRACT_NAME.sol:CONTRACT_NAME --network <network> --constructor-args arguments.js DEPLOYED_CONTRACT_ADDRESS

Verify Contract Programmatically

Verify the contract using verifyContract function in verify.js

Set etherscan api key in .env file or using command

$ ETHERSCAN_API_KEY="your_api_key"

If you don't already have an api key, use either of one etherscan, bscscan, polygonscan according to the network you want.

Example deploy script with verifyContract function is here

Tasks

flatfile

We often need to flatten our code for verification purposes or any other but the existing default flatten task requires manual copy-paste from terminal and creation of whatever file extension we want but we can automate the creation of the flatten file by using a new flatfile task and providing the contract name with --contract flag

$ npx hardhat flatfile --contract CONTRACT_NAME
or
$ yarn flatfile:contract CONTRACT_NAME

where, CONTRACT_NAME can be for example TestingContract

Syntax Highlighting

If you use VSCode, you can enjoy syntax highlighting for your Solidity code via the vscode-solidity extension. The recommended approach to set the compiler version is to add the following fields to your VSCode user settings or in workspace settings json file:

{
  "solidity.compileUsingRemoteVersion": "v0.8.4+commit.c7e474f2",
  "solidity.defaultCompiler": "remote"
}

Where of course v0.8.4+commit.c7e474f2 can be replaced with any other version.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published