In this tutorial you will set up a basic template for a ZetaChain smart contract project. You will then be able to use this template for any of the following tutorials.
If you prefer to skip the setup step and dive into coding, you can clone the template Hardhat project and jump directly to the next tutorial.
- Node.js installed (version 16 or higher)
- Yarn package manager installed (optional, but recommended)
Create a new project directory
Open your terminal and create a new project directory called
Change to the newly created directory:
Initialize the project
Initialize a new Node.js project with default settings:
npm init -y
Add the necessary development dependencies:
yarn add --dev hardhat dotenv @zetachain/addresses-tools envfile @zetachain/addresses @zetachain/interfaces @zetachain/faucet-cli
Initialize the Hardhat project:
Choose the "Create a TypeScript project" option when prompted and agree to all the following prompts.
Remove unnecessary files
The Hardhat template comes with an example “Lock” contract. We will write our own contract in the following sections, so you can safely remove these files.
rm contracts/Lock.sol test/Lock.ts scripts/deploy.ts
Add two import statements:
dotenv package, which is used to manage environment
variables, and the
getHardhatConfigNetworks function from the
@zetachain/addresses-tools package, which will help configure the networks.
dotenv.config() is called to load environment variables from a
created in the previous step. Then, we check if the
variable is defined. If it is, we create an array containing the private key as
a string with a
...getHardhatConfigNetworks(PRIVATE_KEYS) spreads the networks' configuration
returned by the function and passes the
PRIVATE_KEYS array as an argument.
This will add all the networks that ZetaChain supports to the Hardhat
Create helper tasks
Create a task that will generate new account and optionally save them to the
Create a task that will query the ZetaChain faucet for tokens:
Create a task that will query ZetaChain for token balances:
Great start! You now have a template you can use to build your ZetaChain dapps. In the next tutorial you will learn how to create a simple "Hello Zeta" smart contract.