Skip to content
This repository has been archived by the owner on Oct 3, 2024. It is now read-only.

Commit

Permalink
chore(hardhat-plugins): update docs with richier description and bett…
Browse files Browse the repository at this point in the history
…er structure (#880)
  • Loading branch information
kiriyaga-txfusion authored Feb 1, 2024
1 parent b0b7e95 commit c506836
Show file tree
Hide file tree
Showing 13 changed files with 259 additions and 187 deletions.
1 change: 1 addition & 0 deletions docs/.vuepress/sidebar/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ export const enSidebar = sidebar({
"/build/tooling/hardhat/hardhat-zksync-verify-vyper.md",
"/build/tooling/hardhat/hardhat-zksync-ethers.md",
"/build/tooling/hardhat/hardhat-zksync-toolbox.md",
"/build/tooling/hardhat/hardhat-zksync-node.md",
"/build/tooling/hardhat/other-plugins.md",
]
},
Expand Down
53 changes: 51 additions & 2 deletions docs/build/tooling/hardhat/compiling-libraries.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,62 @@ contract Main {
}
```

If you try to create a project with these two files following the guidelines from the [getting started](./getting-started.md) guide, the `yarn hardhat compile` command will fail with the following error:
::: info Support for missing libraries in hardhat-zksync-solc ^0.4.2

Version 0.4.2 introduced a mode that detects non-inlinable libraries that are missing and that are required for the compilation of contracts.

:::

If you try to create a project with these two files following the guidelines from the [getting started](./getting-started.md) guide, the `yarn hardhat compile` command will fail.

#### Using hardhat-zksync-solc version >= 0.4.2

Following error:

```
zksolc compiler detected missing libraries! For more details, visit: https://era.zksync.io/docs/tools/hardhat/compiling-libraries.html.
To compile and deploy libraries, please run: `yarn hardhat deploy-zksync:libraries --private-key <PRIVATE_KEY>`
For more details on how to use deploy-zksync:libraries task from hardhat-zksync-deploy plugin, visit: https://era.zksync.io/docs/tools/hardhat/hardhat-zksync-deploy.html.
```

To address the error, you can follow the instructions provided in the output, which is the recommended approach. For more details, please refer to [this section](#automatic-deployment).
Alternatively, if you prefer a manual resolution for the libraries, you can find detailed instructions in [this section](#manual-deployment).

Choose the method that best suits your preferences or requirements.

#### Using hardhat-zksync-solc version < 0.4.2

Following error:

```
Error in plugin @matterlabs/hardhat-zksync-solc: LLVM("Library `contracts/MiniMath.sol:MiniMath` not found")
```

That error tells us that the address of the `MiniMath` library should be provided.
The error indicates that the compilation process is expecting the address of the MiniMath library, but it is not being provided.

To resolve the error, it's necessary to manually resolve the libraries. For detailed instructions, please refer to [this section](#automatic-deployment).

## Non-inline libraries deployment

### Automatic deployment

::: note
This approach is effective only with specific plugin versions:

- `hardhat-zksync-solc` >= 0.4.2
- `hardhat-zksync-deploy` >= 0.6.5

Make sure that you are using the specified versions or a later versions to ensure compatibility with the described resolution method.
:::

::: note
Vyper does not support automatic deployment of missing libraries, and the process needs to be handled manually.
:::

`hardhat-zksync-deploy` plugin has the capability to automatically deploy all missing libraries generated by compiler. For additional information, you may refer to the [documentation](./hardhat-zksync-deploy.md/#compilation-and-deployment-support-for-missing-libraries). This documentation provides details on how the tool handles the compilation and deployment of libraries that are currently missing.

### Manual deployment

To resolve the issue, you need to create _a separate project_, where only the library file will be located. After deploying _only_ the library to zkSync Era, you should get the address of the deployed library and pass it to the compiler settings. The process of deploying the library is the same as deploying a smart contract. You can learn how to deploy smart contracts on zkSync Era in the [getting started](./getting-started.md#compile-and-deploy-a-contract) guide.

Expand Down
71 changes: 56 additions & 15 deletions docs/build/tooling/hardhat/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ head:

# Getting started

::: warning Windows as platform
If you are using Windows, we strongly recommend you use Windows Subsystem for Linux (also known as WSL 2). You can use `Hardhat` and `Hardhat zkSync plugins` without it, but it will work better if you use it.

To install Node.js using WSL 2, please read this [guide](https://learn.microsoft.com/en-us/windows/dev-environment/javascript/nodejs-on-wsl)
:::

[Hardhat](https://hardhat.org) is an Ethereum development environment, designed for easy smart contract development in Solidity. One of its most prominent features is extendability: you can easily add new plugins to your hardhat project.

zkSync Era has the following official plugins for Hardhat:
Expand All @@ -19,6 +25,7 @@ zkSync Era has the following official plugins for Hardhat:
- [@matterlabs/hardhat-zksync-verify-vyper](./hardhat-zksync-verify-vyper.md) - used to verify vyper smart contracts.
- [@matterlabs/hardhat-zksync-upgradable](./hardhat-zksync-upgradable.md) - used to deploy, update, and verify proxy smart contracts.
- [@matterlabs/hardhat-zksync-ethers](./hardhat-zksync-ethers.md) - wrapper around zksync-ethers with some extra Hardhat-specific functionality.
- [@matterlabs/hardhat-zksync-node](./hardhat-zksync-node.md) - used to run the zkSync era-test-node locally.

::: tip Additional plugins
Learn more about [other plugins from the community](./other-plugins.md) that you can use with zkSync Era.
Expand All @@ -33,7 +40,7 @@ If you are using Vyper, check out the [Vyper plugin documentation](./hardhat-zks
## Prerequisites

- Make sure your machine satisfies the [system requirements](https://github.com/matter-labs/era-compiler-solidity/tree/main#system-requirements).
- A Node and `yarn` package manager installed.
- You have a Node installation and `yarn` or `npm` package manager.
- You are already familiar with deploying smart contracts on zkSync. If not, please refer to the first section of the
- A wallet with sufficient Sepolia or Göerli `ETH` on Ethereum and zkSync Era Testnet to pay for deploying smart contracts. You can get Sepolia ETH from the [network faucets](../../tooling/network-faucets.md).
- Get testnet `ETH` for zkSync Era using [bridges](https://zksync.io/explore#bridges) to bridge funds to zkSync.
Expand All @@ -53,10 +60,18 @@ Skip the hassle for test ETH by using `zksync-cli` for local testing. Simply exe

To create a new project run the CLI's `create` command, passing a project name:

#### Solidity project

```sh
npx zksync-cli create demo --template hardhat_solidity
```

#### Vyper project

```sh
npx zksync-cli create demo --template hardhat_vyper
```

This command creates a `demo` folder and clones a Hardhat template project inside it. The downloaded project is already configured and contains all the required plugins.

::: tip Migrating a project
Expand All @@ -69,11 +84,43 @@ The `hardhat.config.ts` file contains some zkSync-Era-specific configurations:

The zkSync Era deployment and compiler plugin imports.

###### Solidity project

```typescript
import "@matterlabs/hardhat-zksync-deploy";
import "@matterlabs/hardhat-zksync-solc";
......
```

The `zksolc` block contains the minimal configuration for the compiler.

```typescript
zksolc: {
version: "latest", // Uses latest available in https://github.com/matter-labs/zksolc-bin/
settings: {},
},
```

###### Vyper project

```typescript
import "@nomiclabs/hardhat-vyper";
import "@matterlabs/hardhat-zksync-deploy";
import "@matterlabs/hardhat-zksync-vyper";
......
```

The `zkvyper` block contains the minimal configuration for the compiler.

```typescript
zkvyper: {
version: "latest", // Uses latest available in https://github.com/matter-labs/zkvyper-bin/
settings: {},
},
```

#### Network

The network endpoints of the `zkSyncTestnet` network change dynamically for local tests.

```typescript
Expand All @@ -100,15 +147,6 @@ For local zkSync testing, modify `url` and `ethNetwork` in `hardhat.config.ts` t
This template project includes a basic unit test in the `/test` folder that runs with the local-setup and can be executed with `yarn test`. Learn more about how to [start the local setup and write unit tests here](../../test-and-debug/getting-started.md).
:::

The `zksolc` block contains the minimal configuration for the compiler.

```typescript
zksolc: {
version: "latest", // Uses latest available in https://github.com/matter-labs/zksolc-bin/
settings: {},
},
```

::: tip Advanced configuration
To learn more about each specific property in the `hardhat.config.ts` file, check out the [plugins documentation](../hardhat/getting-started.md)
:::
Expand All @@ -125,9 +163,9 @@ Your private key will be used for paying the costs of deploying the smart contra

## Compile and deploy a contract

Smart contracts belong in the `contracts` folder. The template project contains a simple `Greeter.sol` contract and a script to deploy it.
Smart contracts belong in the `contracts` folder.

1. To compile the contract, run:
#### 1. To compile the contract, run

```sh
yarn hardhat compile
Expand All @@ -138,6 +176,7 @@ You'll see the following output:
```text
Compiling 1 Solidity file
Successfully compiled 1 Solidity file
// Successfully compiled 1 Vyper file - Vyper project
✨ Done in 1.09s.
```

Expand All @@ -148,7 +187,7 @@ The `artifacts-zk` and `cache-zk` folders are included in the `.gitignore` file.

:::

The `deploy-greeter.ts` script is in the `deploy` folder. This script uses the `Deployer` class from the `hardhat-zksync-deploy` package to deploy the `Greeter.sol` contract.
The `deploy-greeter.ts` script is in the `deploy` folder. This script uses the `Deployer` class from the `hardhat-zksync-deploy` package to deploy the `Greeter.sol`/`Greeter.vy` contract.

```typescript
import { Wallet, utils } from "zksync-ethers";
Expand Down Expand Up @@ -205,7 +244,7 @@ export default async function (hre: HardhatRuntimeEnvironment) {
}
```

2. To execute the deployment script run:
#### 2. To execute the deployment script run

```sh
yarn hardhat deploy-zksync --script deploy-greeter.ts
Expand Down Expand Up @@ -248,8 +287,10 @@ import { HardhatRuntimeEnvironment } from "hardhat/types";
import dotenv from "dotenv";
dotenv.config();

// load contract artifact. Make sure to compile first!
// load contract artifact. Make sure to compile first! - Solidity Project
import * as ContractArtifact from "../artifacts-zk/contracts/Greeter.sol/Greeter.json";
// load contract artifact. Make sure to compile first! - Vyper Project
//import * as ContractArtifact from "../artifacts-zk/contracts/Greeter.vy/Greeter.json";

const PRIVATE_KEY = process.env.WALLET_PRIVATE_KEY || "";

Expand Down
25 changes: 16 additions & 9 deletions docs/build/tooling/hardhat/hardhat-zksync-deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ This plugin provides utilities for deploying smart contracts on zkSync Era with

To use the `hardhat-zksync-deploy` in your project, we recommend that:

- You have a Node installation and `yarn` package manager.
- You have a Node installation and `yarn` or `npm` package manager.
- You are already familiar with deploying smart contracts on zkSync Era. If not, please refer to the first section of the [quickstart tutorial](../../quick-start/hello-world.md).
- You have a wallet with sufficient Sepolia `ETH` on L1 to pay for bridging funds to zkSync as well as deploying smart contracts. Use the [network faucets](../../tooling/network-faucets.md) to get some test tokens in your account.
- You know how to get your [private key from your MetaMask wallet](https://support.metamask.io/hc/en-us/articles/360015289632-How-to-export-an-account-s-private-key).
- A wallet with sufficient Sepolia `ETH` on Ethereum and zkSync Era Testnet to pay for deploying smart contracts on testnet. You can get Sepolia ETH from the [network faucets](../../tooling/network-faucets.md).
- Get testnet `ETH` for zkSync Era using [bridges](https://zksync.io/explore#bridges) to bridge funds to zkSync.
- You know [how to get your private key from your MetaMask wallet](https://support.metamask.io/hc/en-us/articles/360015289632-How-to-export-an-account-s-private-key).

::: tip Local zkSync Testing with zksync-cli
Skip the hassle for test ETH by using `zksync-cli` for local testing. Simply execute `npx zksync-cli dev start` to initialize a local zkSync development environment, which includes local Ethereum and zkSync nodes. This method allows you to test contracts without requesting external testnet funds. Explore more in the [zksync-cli documentation](../zksync-cli/getting-started.md).
:::

::: warning Version Compatibility Warning
Ensure you are using the correct version of the plugin with ethers:
Expand Down Expand Up @@ -141,12 +146,6 @@ To see an example script of how to use a `Deployer` class to deploy a contract,
### Configuration
::: warning API changes in v0.6.x
- We advise developers to upgrade to the most recent version of this package.
:::
In the `hardhat.config.ts` file, specify zkSync Era and Ethereum networks in the `networks` object.
```typescript
Expand Down Expand Up @@ -271,3 +270,11 @@ yarn hardhat deploy-zksync:libraries --private-key 0x7726827caac94a7f9e1b160f7ea
::: tip
In Typescript projects `--exported-config-object <object name>` argument can be provided optionally. Plugin will try to resolve config by `HardhatUserConfig` type.
:::

::: warning Hardhat library auto-population

Using `export default {}` for the Hardhat config is currently not supported for library auto-population. Instead, you should use `export const config = {}`, and make sure to add `export default config;` at the bottom of the file.

The default object name is `config`, but you can replace it with a different object name using the `--exported-config-object <object name>` command. This allows you to customize the exported object for your Hardhat configuration.

:::
32 changes: 25 additions & 7 deletions docs/build/tooling/hardhat/hardhat-zksync-ethers.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ interface FactoryOptions {
wallet?: zk.Wallet;
}

function provider: () => zk.Provider;
function providerL2: () => zk.Provider;
function providerL1: () => ethers.Provider;
function getWallet: (privateKeyOrIndex?: string | number) => zk.Wallet;
function getContractFactory: (name: string, wallet?: zk.Wallet, deploymentType?: DeploymentType) => Promise<zk.ContractFactory>;
function getContractFactory: (abi: any[], bytecode: ethers.BytesLike,wallet?: Wallet,deploymentType?: DeploymentType) => Promise<zk.ContractFactory>;
Expand All @@ -102,7 +103,8 @@ function loadArtifact: (name: string) => Promise<ZkSyncArtifact>;
function deployContract: (artifact: ZkSyncArtifact, constructorArguments: any[], wallet?: zk.Wallet, overrides?: ethers.Overrides, additionalFactoryDeps?: ethers.BytesLike[]) => Promise<zk.Contract>;
```

- `provider()` - returns a `zk.Provider` automatically connected to the selected network.
- `providerL2()` - retruns a `zk.Provider` for L2, automatically connected to the selected network.
- `providerL1()` - retruns a `ethers.Provider` for L1, automatically connected to the selected network.
- `getWallet(privateKeyOrIndex?: string | number)` - returns `zk.Wallet` for the given private key or index. If the network is set to local and the private key is not provided, the method will return a wallet for rich accounts with the default index of `0` or the specified index. If the `accounts` object is set in the hardhat config and the private key is not specified, the method will return the wallet for the given account with the default index `0` or for the specified index.
- `getWallets()` - returns all wallets of type `zk.Wallet`. If the network is set to local, the method will return wallets for rich accounts. If the `accounts` object is set in the hardhat config for the used network, the method will return the wallets for the provided accounts.
- `getContractFactory(name: string, wallet?: zk.Wallet, deploymentType?: DeploymentType)` - returns a `zk.ContractFactory` for provided artifact name.
Expand All @@ -129,7 +131,10 @@ Task usage:

```ts
task("getFeeData", "Returns a fee data.").setAction(async (hre) => {
return await hre.zksyncEthers.provider.getFeeData();
const feeDataL2 = await hre.zksyncEthers.providerL2.getFeeData();
const feeDataL1 = await this.env.zksyncEthers.providerL1.getFeeData();

return { feeDataL2, feeDataL1 };
});
```

Expand All @@ -140,12 +145,11 @@ export default async function (hre: HardhatRuntimeEnvironment) {
console.info(chalk.yellow(`Running deploy`));

//automatically connected to the selected network
const gasPrice = await hre.zksyncEthers.provider.send("eth_gasPrice", []);
assert.strictEqual("0xee6b280", gasPrice);
const gasPrice = await hre.zksyncEthers.providerL2.send("eth_gasPrice", []);

//getContractFactory with default wallet
//getContractFactory with default wallet, deploy contract and set new greeting message
const greeterFactory = await hre.zksyncEthers.getContractFactory("Greeter");
const greeter = (await greeterFactory.deploy("Hello, world!")) as zk.Contract;
const greeter = await greeterFactory.deploy("Hello, world!");

console.info(chalk.green(`Greeter deployed to: ${await greeter.getAddress()}`));

Expand All @@ -155,7 +159,21 @@ export default async function (hre: HardhatRuntimeEnvironment) {
await tx.wait();
console.info(chalk.green(`Greeter greeting set to: ${await greeter.greet()}`));

// deploy with provided wallet using loadArtifact and deployContract
const wallet = await hre.zksyncEthers.getWallet("0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110");
console.info(chalk.green(`Wallet address: ${await wallet.getAddress()}`));

// deposit ETH from L1 to L2 to cover costs of deployment
const depositHandle = await wallet.deposit({
to: wallet.address,
token: utils.ETH_ADDRESS,
amount: ethers.parseEther("0.001"),
});
await depositHandle.wait();

const artifact = await hre.zksyncEthers.loadArtifact("Greeter");
const greets = await hre.zksyncEthers.deployContract(artifact, ["Hello, world!"], wallet);
console.info(chalk.green(`Greeter deployed to: ${await greets.getAddress()}`));
console.info(chalk.green(`Greeter greeting set to: ${await greets.greet()}`));
}
```
5 changes: 3 additions & 2 deletions docs/build/tooling/hardhat/hardhat-zksync-node.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ Ensure you are using the correct version of the plugin with ethers:

- For plugin version **≥1.0.0**:
- Compatible with ethers **v6** (⭐ Recommended)
:::

:::

## Installation

Expand All @@ -37,7 +38,7 @@ Add the latest version of this plugin to your project with the following command
@tab:active yarn

```bash
yarn add -D @matterlabs/hardhat-zksync-node
yarn add -D @matterlabs/hardhat-zksync-node zksync-ethers ethers
```

@tab npm
Expand Down
Loading

0 comments on commit c506836

Please sign in to comment.