Installation
How to install hardhat-zksync for your project.
Before starting development with Hardhat and ZKsync, it's important to have your environment correctly configured. This guide will help you set up a Validium project using the ZKsync CLI, a tool that simplifies the process by providing pre-built templates with all necessary Hardhat plugins.
If you're migrating an existing Hardhat project to zksync-era
, please refer to the migration guide for detailed instructions.
Prerequisites
System requirements
Ensure your machine meets the system requirements for running ZKsync and Hardhat. For Windows users, using Windows Subsystem for Linux (WSL 2) is highly recommended for better compatibility.
Node.js and package manager
Node.js version 18 or newer is required. You can install it from the official Node.js website.
Basic knowledge of Ethereum development
Familiarity with Ethereum development, including deploying smart contracts. If you are new to this, review the Contract Deployment documentation.
Wallet and testnet funds
A wallet with VLDM is needed to deploy contracts. Visit the Network Faucets page to get testnet funds.
Install ZKsync CLI
The ZKsync CLI makes it easy to set up a project and perform local testing by providing pre-configured templates. To install the ZKsync CLI globally, use npm or yarn:
npmyarn
Skip the hassle for test ETH by using zksync-cli
for local testing. Use the npx zksync-cli dev start
command to initialize a local ZKsync development environment, which includes local Ethereum and Validium nodes. This method allows you to test contracts without requesting external testnet funds. Explore more in the zksync-cli documentation.
Set Up a new project
Create a new project
Use the ZKsync CLI to create a new Hardhat project. Replace <project-name>
with your desired project name. This command will create a <project-name>
folder and clone a Hardhat template project into it. Choose the template based on your preferred contract language (Solidity or Vyper):
SolidityVyper
This creates a project folder that is already configured and contains all the required plugins for Validium development.
Configure your environment
Environment variables:
Rename the
.env.example
file in your project directory to.env
.Add your wallet’s private key to the
.env
file:
Security tip: Use burner wallets for development and testing to avoid using real private keys, which could lead to security risks.
Check configuration:
Open the
hardhat.config.ts
file to confirm the configurations for ZKsync are correct. The default setup should already include the necessary settings for deploying and interacting with smart contracts on Validium.
Compile and deploy your contracts
Compile contracts
Ensure your smart contracts are located in the contracts
folder of your project. To compile them, use:
yarnnpx
This will compile your contracts and generate the necessary artifacts in the artifacts-zk
and cache-zk
folders.
Contracts must be compiled using the official Validium compilers, with their respective Hardhat plugins.
Contracts compiled with other compilers will fail to deploy to Validium.
Deploy contracts
Deploy your contracts using Hardhat scripts. A basic deployment script is usually included in the template project (deploy/deploy-greeter.ts
):
This script will deploy your smart contracts to the specified Validium testnet.
For more detailed instructions on deploying and testing, refer to the Getting Started guide.
Testing and interaction
Once deployed, you can interact with your smart contracts using scripts included in your project. Make sure to update these scripts with the correct contract addresses and any other required parameters.
Last updated