hardhat-zksync
Description
The hardhat-zksync
plugin is a comprehensive bundle of ZKsync-related Hardhat plugins that provides:
- Simplified integration of ZKsync functionality into Hardhat projects
- Unified interface for deploying and managing smart contracts on ZKsync Era
- Contract verification support for both ZKsync Explorer and Etherscan
Resources:
- For plugin version <1.0.0:
- Compatible with ethers v5
- For plugin version ≥1.0.0:
- Compatible with ethers v6 (⭐ Recommended)
Installation
Prerequisites
- Node.js version 18 or higher
- Hardhat version 2.18.0 or higher
Setup
Install the plugin using your preferred package manager:
yarn add -D @matterlabs/hardhat-zksync
Import the package in your hardhat.config.ts
file:
import "@matterlabs/hardhat-zksync";
Configuration
The plugin serves as a bundle for other plugins and doesn't require specific configuration itself. However, you can configure the individual plugins it includes:
Plugin | Configuration Options |
---|---|
hardhat-zksync-solc | See hardhat-zksync-solc |
hardhat-zksync-deploy | See hardhat-zksync-deploy |
hardhat-zksync-upgradable | See hardhat-zksync-upgradable |
hardhat-zksync-verify | See hardhat-zksync-verify |
hardhat-zksync-node | See hardhat-zksync-node |
hardhat-zksync-ethers | See hardhat-zksync-ethers |
Example Configuration
import "@matterlabs/hardhat-zksync";
import { HardhatUserConfig } from "hardhat/config";
const config: HardhatUserConfig = {
zksolc: {
version: "1.5.12",
compilerSource: "binary",
settings: {
optimizer: {
enabled: true,
mode: '3'
}
}
},
networks: {
ZKsyncTestnet: {
url: "https://testnet.era.zksync.dev",
ethNetwork: "sepolia",
zksync: true
}
}
};
export default config;
Additions
Extended Tasks
For certain tasks present in the plugins encompassed by this plugin, it overrides them with new features and parameters. These tasks streamline common functionalities into a simplified workflow. Here is a list of overriden tasks where this plugin adds new optional parameter --verify:
deploy-zksync:contract
- Deploys contracts to ZKsync Eradeploy-zksync:proxy
- Deploys proxy contractsupgrade-zksync:proxy
- Upgrades proxy contractsdeploy-zksync:beacon
- Deploys beacon contractsupgrade-zksync:beacon
- Upgrades beacon contracts
Added HRE Extensions
This plugin includes all HRE extensions from the contained plugins, providing a unified interface for ZKsync-specific functionality.
Commands
Command | Description | Parameters |
---|---|---|
deploy-zksync:contract | Deploys a contract to ZKsync Era | --verify (optional): Automatically verifies the contract after deployment |
deploy-zksync:proxy | Deploys a proxy contract | --verify (optional): Automatically verifies the proxy contract after deployment |
upgrade-zksync:proxy | Upgrades a proxy contract | --verify (optional): Automatically verifies the upgraded contract |
deploy-zksync:beacon | Deploys a beacon contract | --verify (optional): Automatically verifies the beacon contract after deployment |
upgrade-zksync:beacon | Upgrades a beacon contract | --verify (optional): Automatically verifies the upgraded beacon contract |
Usage
After installing and configuring the plugin, you can use any of the included plugins' functionality in your project. The plugin provides a unified interface for:
- Deploying contracts to ZKsync Era
- Verifying contracts on ZKsync Explorer and Etherscan
- Managing upgradeable contracts
- Using ZKsync-specific ethers.js implementation
- Running local ZKsync node for development
For detailed usage instructions for each specific plugin, refer to their individual documentation pages:
- hardhat-zksync-solc
- hardhat-zksync-deploy
- hardhat-zksync-upgradable
- hardhat-zksync-verify
- hardhat-zksync-node
- hardhat-zksync-ethers
Troubleshooting
Plugin Not Found
Problem: Error message "Plugin not found" or missing functionality
Solutions:
- Ensure plugin is installed:
npm i -D @matterlabs/hardhat-zksync
- Verify plugin import in
hardhat.config.ts
:import "@matterlabs/hardhat-zksync";
For more specific troubleshooting guidance, refer to the documentation of the individual plugins you're using.
For more help, please refer to the GitHub issues.