hardhat-example provides a simple smart contract deployment framework using the Hardhat development kit on Quai Network.
This project demonstrates a basic Hardhat use case. It comes with a few sample contracts, and a script that deploys a contract.
hardhat: Development toolkit- SolidityX: A fork of the Solidity compiler that supports Quai Network's QRC20 and QRC721 token standards
- Nodejs: Javascript runtime engine
@nomicfoundation/hardhat-toolbox: Hardhat utilsquaisandquais-polling: Javascript SDK for interacting with Quai Networkquai-hardhat-plugin: A plugin that installs the SolidityX compiler for use with Hardhat.dotenv: A zero-dependency module that securely loads environment variables.
- Clone
hardhat-example
git clone https://github.com/dominant-strategies/hardhat-example- Install package dependencies
npm iThere are two methods of installing the SolidityX compiler for use with Hardhat:
- Install the SolidityX compiler via
quai-hardhat-plugin(Recommended) - Install and build the SolidityX compiler from source
If you've installed quai-hardhat-plugin already, the SolidityX compiler will be installed automatically when you run npx hardhat compile for MacOS and Linux users. Windows is not currently supported by the plugin.
Note: Building the compiler from source still requires the quai-hardhat-plugin to be installed.
Visit the SolidityX Repository for instructions on how to clone and build the SolidityX compiler for your specific operating system.
Once you've built the SolidityX compiler, you'll need to add path to your solc binary into the customCompilerPath variable in the hardhat.config.js file. The file already includes common paths for MacOS and Linux as comments.
- Copy
.env.distto.env.
cp .env.dist .env- Define network variables inside of the
.envfile.- Private Keys
- The sample environment file is configured with a placeholder private key for each chain.
- Replace the placeholder private key for each chain with your own private key that corresponds to the address you want to deploy from.
- You cannot use the same private key for each chain.
- Chain ID
- Depending on the network you're deploying to, you'll need to set the
CHAINIDvariable to the correct chain ID.- Local:
1337 - Testnet:
9000 - Devnet:
12000
- Local:
- Depending on the network you're deploying to, you'll need to set the
- RPC Endpoints
- Private Keys
- Configure the
deploy.jsscript to specify the contract you'd like to deploy- Pass the name of the contract into the hardhat runtime contract definition
- Pass relevant constructor arguments into the deploy command (i.e. the intial greeting for the
greeter.solcontract)
- Compile contracts using
npx hardhat compile - Deploy contract to a single chain using
npx hardhat run scripts/deploy.js- This will deploy to the
defaultNetworkspecified in yourhardhat.config.js - You can specify a network other than the
defaultNetworkby passing the--network networkNameflag to the deploy command. ReplacenetworkNamewith one of the options below. - Available
networkNameare:cyprus1cyprus2cyprus3paxos1paxos2paxos3hydra1hydra2hydra3
- This will deploy to the
The deployQRC20.js and deployQRC721.js scripts have been included as a simple method of deploying QRC20 and QRC721 contracts to a single chain within Quai Network.
To specify token details (token name, ticker, supply, etc) for either the QRC20 or QRC721 contract, modify the constructorArgs object in the deploy script.
Hardhat has a number of other useful CLI commands.
npx hardhat compile
npx hardhat clean
npx hardhat test
npx hardhat help