A guide to deploying a simple single-chain smart contract on Quai Network.
NodeJS | Javascript runtime environment. Use the LTS version. |
hardhat-example | A Hardhat project with sample contracts and deploy scripts for Quai Network. |
Quais.js | A JavaScript library for interacting with Quai Network. |
hardhat-example
repository, navigating to the Solidity
directory we’ll be using for this tutorial, and installing the dependencies via npm
.
Solidity/
directory comes with 2 sample contracts: ERC20.sol
and ERC721.sol
inside of the contracts/
directory. Both contracts are implementations derived from the Open Zeppelin library.
We’ll be using the ERC20.sol
sample contract for this tutorial, but you can also add your own contracts or use contracts from other libraries.
.env.dist
, file at the root of the hardhat-example
repo to manage token details, private keys, and your RPC URL in a secure fashion.
.env.dist
file is a template file and should not be used as is. You should copy the .env.dist
file to a new .env
file.This file lives at the root of the hardhat-example
repository and serves as the config file for the Solidity/
directory..env.dist
file in the root to a new .env
file in the repository root using the following command:
.env
file and add your private keys, RPC URLs, and token args for the contract you’d like to deploy. The .env
file should look like this:
PK
values must all be for unique addresses and correspond to the zone
name, i.e. your CYPRUS1_PK
should be the private key of your Cyprus1
address.hardhat-example
repository uses the Quais SDK to configure network connections using only a single RPC URL. To learn more about how the SDK configures network providers, visit the SDK provider examples section.
After filling in your private keys, RPC URL, we’re now ready to securely consume them inside of hardhat.config.js
.
hardhat.config.js
file to configure smart contract deployments. The config file allows you to define deployment networks, tasks, compilers, etc.
hardhat-example
contains a prebuilt hardhat.config.js
file with configurations for deploying and verifying smart contracts on any shard in the network.
Sample hardhat configuration file
hardhat-example
repository.cyprus1
cyprus2
cyprus3
paxos1
paxos2
paxos3
hydra1
hydra2
hydra3
hardhat.config.js
will pull your private keys and RPC URL from the .env
file and use them to deploy and verify your contracts. You can also specify the Solidity version and compiler settings in the solidity
object.
Compile with Hardhat
npx
in the CLI.Compile all of the contracts inside the contracts/
directory with:Configure deployment scripts
scripts/
directory, you’ll find a deploy script for both the ERC20 and ERC721 contracts: deployERC20.js
and deployERC721.js
. For this tutorial, we’ll be deploying an ERC20 contract.The deployERC20.js
script pulls your network configuration from hardhat.config.js
and your token arguments from the .env
file at the root of the repository and uses them to deploy your contract.Token arguments are consumed via the tokenArgs
array:provider
and wallet
variables in tandem with the compiled contract ABI and bytecode to create a new contract instance:deployERC721.js
script functions in a similar manner, but with different contract arguments and a different contract ABI and
bytecode. You can replicate this configuration for any contract you’d like to deploy.Deploy your contract
--network
flag to specify the network you’d like to deploy to (available options can be found here). For this tutorial, we’ll be deploying to cyprus1
.ERC20.sol
and ERC721.sol
sample contracts are basic implementations of each token for example purposes. It is highly recommended
to modify these contracts to fit your specific use case before deploying them for any production use.Interact with the contract
0x00735E9B2c731Fd3eCC8129a3653ACb99dF969cC
to get the name, symbol, and total supply of the token.