hardhat-zksync

Guide on using the hardhat-zksync plugin.

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:

Ensure you are using the correct version of the plugin with ethers:
  • For plugin version <1.0.0:
    • Compatible with ethers v5
  • For plugin version ≥1.0.0:
    • Compatible with ethers v6 (⭐ Recommended)
Examples in this documentation are for plugin version >=1.0.0

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:

PluginConfiguration Options
hardhat-zksync-solcSee hardhat-zksync-solc
hardhat-zksync-deploySee hardhat-zksync-deploy
hardhat-zksync-upgradableSee hardhat-zksync-upgradable
hardhat-zksync-verifySee hardhat-zksync-verify
hardhat-zksync-nodeSee hardhat-zksync-node
hardhat-zksync-ethersSee 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 Era
  • deploy-zksync:proxy - Deploys proxy contracts
  • upgrade-zksync:proxy - Upgrades proxy contracts
  • deploy-zksync:beacon - Deploys beacon contracts
  • upgrade-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

CommandDescriptionParameters
deploy-zksync:contractDeploys a contract to ZKsync Era--verify (optional): Automatically verifies the contract after deployment
deploy-zksync:proxyDeploys a proxy contract--verify (optional): Automatically verifies the proxy contract after deployment
upgrade-zksync:proxyUpgrades a proxy contract--verify (optional): Automatically verifies the upgraded contract
deploy-zksync:beaconDeploys a beacon contract--verify (optional): Automatically verifies the beacon contract after deployment
upgrade-zksync:beaconUpgrades 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:

  1. Deploying contracts to ZKsync Era
  2. Verifying contracts on ZKsync Explorer and Etherscan
  3. Managing upgradeable contracts
  4. Using ZKsync-specific ethers.js implementation
  5. Running local ZKsync node for development

For detailed usage instructions for each specific plugin, refer to their individual documentation pages:

Troubleshooting

Plugin Not Found

Problem: Error message "Plugin not found" or missing functionality

Solutions:

  1. Ensure plugin is installed:
    npm i -D @matterlabs/hardhat-zksync
    
  2. 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.


Made with ❤️ by the ZKsync Community