Skip to content

Commit

Permalink
chore: update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
itsacoyote committed May 16, 2024
1 parent 60add91 commit fe62d7d
Show file tree
Hide file tree
Showing 55 changed files with 3,066 additions and 2,648 deletions.
11 changes: 11 additions & 0 deletions content/_partials/callout-zksync-cli.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
title: Callout zkSync CLI
---

::callout{icon="i-heroicons-light-bulb"}
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](https://docs.zksync.io/build/tooling/zksync-cli).
::
197 changes: 100 additions & 97 deletions content/tutorials/cross-chain-governance/10.index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,16 @@ This tutorial shows you how to implement communication between L1 and L2 with th
- You are already familiar with deploying smart contracts on zkSync Era.
If not, please refer to the first section of the [quickstart tutorial](https://docs.zksync.io/build/quick-start).
- You already have some experience working with Ethereum.
- A wallet with sufficient Sepolia `ETH` on Ethereum and %%zk_testnet_name%% to pay for deploying smart
contracts. You can get Sepolia ETH from the [network faucets](../../tooling/network-faucets.md).
- A wallet with sufficient Sepolia `%%zk_testnet_currency_symbol%%` on Ethereum and %%zk_testnet_name%% to pay for deploying smart
contracts. You can get Sepolia ETH from the [network faucets](https://docs.zksync.io/ecosystem/network-faucets).
- 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).
- 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).

::callout{icon="i-heroicons-light-bulb"} 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](../../tooling/zksync-cli/getting-started.md). ::
:display-partial{path="/_partials/callout-zksync-cli"}

### Complete Project

Download the complete project [here](https://github.com/matter-labs/tutorials/tree/main/cross-chain).
Download the [complete project on GitHub](https://github.com/matter-labs/tutorials/tree/main/cross-chain).

## Project Setup

Expand All @@ -44,8 +40,10 @@ folder.
mkdir L1-governance
```

::callout{icon="i-heroicons-exclamation-circle"} The `L1-governance` code is a default Hardhat project used to deploy a
contract on L1. The `L2-counter` code includes all zkSync dependencies and configurations for L2. ::
::callout{icon="i-heroicons-exclamation-circle"}
The `L1-governance` code is a default Hardhat project used to deploy a contract on L1.
The `L2-counter` code includes all zkSync dependencies and configurations for L2.
::

## L1 Governance

Expand All @@ -59,15 +57,20 @@ npx hardhat

Select the option **Create a Typescript project** and accept the defaults for everything else.

::callout{icon="i-heroicons-exclamation-circle"} To interact with the zkSync bridge contract using Solidity, you need
::callout{icon="i-heroicons-exclamation-circle"}
To interact with the zkSync bridge contract using Solidity, you need
the zkSync contract interface. There are two ways to get it:

- Import it from the `@matterlabs/zksync-contracts` npm package (preferred).
- Download it from the [contracts repo](https://github.com/matter-labs/era-contracts). ::
- Download it from the [contracts repo](https://github.com/matter-labs/era-contracts).

::

1. Install the following dependencies:

Make sure you use actual node (lts version) and actual npm version ::code-group
Make sure you use actual node (lts version) and actual npm version

::code-group

```bash [npm]
npm i -D typescript ts-node @openzeppelin/contracts @matterlabs/zksync-contracts @nomicfoundation/hardhat-ethers @typechain/ethers-v6 @typechain/hardhat typechain ethers
Expand All @@ -81,20 +84,22 @@ yarn add -D typescript ts-node @openzeppelin/contracts @matterlabs/zksync-contra

### Create L1 Governance Contract

::callout{icon="i-heroicons-light-bulb"} Make sure you're still in the `L1-governance` folder. ::
::callout{icon="i-heroicons-light-bulb"}
Make sure you're still in the `L1-governance` folder.
::

The following Solidity code defines the Governance smart contract.

The constructor sets the contract creator as the single governor. The `callZkSync` function calls a transaction on L2
which can only be called by the governor.
The constructor sets the contract creator as the single governor.
The `callZkSync` function calls a transaction on L2 which can only be called by the governor.

1. Remove existing `/test` directory and any contracts that exist in `/contracts`.

2. `cd` into the `contracts\` folder.
2. `cd` into the `contracts/` folder.

3. Create a file called `Governance.sol` and copy/paste the code below into it.

```solidity
```solidity [Governance.sol]
// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.13;
Expand Down Expand Up @@ -125,98 +130,96 @@ contract Governance {

### Deploy L1 Governance Contract

1. Create the file `L1-Governance/sepolia.json` and copy/paste the code below, filling in the relevant values. Find node
provider urls [here](https://chainlist.org/chain/11155111). You have to connect your wallet to the network and add
the network to the wallet in advance.

`L1-Governance/sepolia.json` file

```json
{
"nodeUrl": "<SEPOLIA NODE URL>",
"deployerPrivateKey": "<YOUR PRIVATE KEY>"
}
```

2. Replace the code in `hardhat.config.ts` with the following:

```ts
import "@nomicfoundation/hardhat-ethers";
import { HardhatUserConfig } from "hardhat/config";

// import file with Sepolia params
const sepolia = require("./sepolia.json");

const config: HardhatUserConfig = {
solidity: {
version: "0.8.20",
},
networks: {
// Sepolia network
sepolia: {
url: sepolia.nodeUrl,
accounts: [sepolia.deployerPrivateKey],
},
},
};

export default config;
```
1. Create the file `L1-Governance/sepolia.json` and copy/paste the code below, filling in the relevant values.
Find node provider urls [here](https://chainlist.org/chain/11155111).
You have to connect your wallet to the network and add the network to the wallet in advance.

3. Navigate to the `scripts` folder and copy/paste the following code into the `deploy.ts` file (removing any previous
```json [L1-Governance/sepolia.json]
{
"nodeUrl": "<SEPOLIA NODE URL>",
"deployerPrivateKey": "<YOUR PRIVATE KEY>"
}
```

1. Replace the code in `hardhat.config.ts` with the following:

```ts
import "@nomicfoundation/hardhat-ethers";
import { HardhatUserConfig } from "hardhat/config";

// import file with Sepolia params
const sepolia = require("./sepolia.json");

const config: HardhatUserConfig = {
solidity: {
version: "0.8.20",
},
networks: {
// Sepolia network
sepolia: {
url: sepolia.nodeUrl,
accounts: [sepolia.deployerPrivateKey],
},
},
};

export default config;
```

1. Navigate to the `scripts` folder and copy/paste the following code into the `deploy.ts` file (removing any previous
code):

```ts
// We require the Hardhat Runtime Environment explicitly here. This is optional
// but useful for running the script in a standalone fashion through `node <script>`.
//
// When running the script with `npx hardhat run <script>` you'll find the Hardhat
// Runtime Environment's members available in the global scope.
import { ethers } from "hardhat";
```ts
// We require the Hardhat Runtime Environment explicitly here. This is optional
// but useful for running the script in a standalone fashion through `node <script>`.
//
// When running the script with `npx hardhat run <script>` you'll find the Hardhat
// Runtime Environment's members available in the global scope.
import { ethers } from "hardhat";
async function main() {
// We get the contract to deploy
const Governance = await ethers.getContractFactory("Governance");
async function main() {
// We get the contract to deploy
const Governance = await ethers.getContractFactory("Governance");
const contract = await Governance.deploy();
const receipt = await contract.deploymentTransaction()?.wait();
const contract = await Governance.deploy();
const receipt = await contract.deploymentTransaction()?.wait();
console.log(`Governance contract was successfully deployed at ${receipt?.contractAddress}`);
}
console.log(`Governance contract was successfully deployed at ${receipt?.contractAddress}`);
}
// We recommend always using this async/await pattern to properly handle errors.
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
```
// We recommend always using this async/await pattern to properly handle errors.
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
```

4. From the `L1-governance` folder root, compile and deploy the contract:
1. From the `L1-governance` folder root, compile and deploy the contract:

::code-group
::code-group

```sh [npm]
# compile contract
npx hardhat compile
```sh [npm]
# compile contract
npx hardhat compile
# deploy contract
npx hardhat run --network sepolia ./scripts/deploy.ts
```
# deploy contract
npx hardhat run --network sepolia ./scripts/deploy.ts
```

```sh [yarn]
# compile contract
yarn hardhat compile
```sh [yarn]
# compile contract
yarn hardhat compile
# deploy contract
yarn hardhat run --network sepolia ./scripts/deploy.ts
```
# deploy contract
yarn hardhat run --network sepolia ./scripts/deploy.ts
```

::
::

You should see output like this:
You should see the following output:

```sh
Governance contract was successfully deployed at 0xf28Df77fa8ff56cA3084bd11c1CAF5033A7b8C4A
```
```sh
Governance contract was successfully deployed at 0xf28Df77fa8ff56cA3084bd11c1CAF5033A7b8C4A
```

Save the address to use in a later step.
Save the address to use in a later step.
Loading

0 comments on commit fe62d7d

Please sign in to comment.