Skip to content

Commit

Permalink
fix: broken tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
uF4No committed Jul 22, 2024
1 parent aa9219f commit cb3d5ee
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 293 deletions.
96 changes: 44 additions & 52 deletions content/tutorials/cross-chain-governance/10.index.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
---
title: L1 governance contract
description: Build and deploy a smart contract in L1 and send transactions that update the state of a contract in zkSync.
description: Build and deploy a smart contract in L1 and send transactions that update the state of a contract in ZKsync.
---

This tutorial shows you how to implement communication between L1 and L2 with the following example:

- A **Governance** Solidity smart contract is deployed on layer 1. This contract has a function that sends a transaction
to zkSync layer 2.
- A **Counter** Solidity smart contract is deployed on zkSync layer 2. This contract stores a number that is incremented
to ZKsync Era layer 2.
- A **Counter** Solidity smart contract is deployed on ZKsync Era layer 2. This contract stores a number that is incremented
by calling the `increment` method. The `Governance` contract on layer 1 calls this function.

## Prerequisites

- Make sure your machine satisfies the [system
requirements](https://github.com/matter-labs/era-compiler-solidity/tree/main#system-requirements).
- You are already familiar with deploying smart contracts on zkSync Era.
- 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 `%%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.
- 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).

:display-partial{path="/_partials/_callout-zksync-cli"}
Expand All @@ -42,7 +42,7 @@ 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.
The `L2-counter` code includes all ZKsync dependencies and configurations for L2.
::

## L1 Governance
Expand All @@ -52,14 +52,14 @@ The `L2-counter` code includes all zkSync dependencies and configurations for L2
2. Run the following to initialise and set up the L1 project:

```sh
npx hardhat
npx hardhat init
```

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
the zkSync contract interface. There are two ways to get it:
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).
Expand All @@ -73,11 +73,11 @@ 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
npm i -D typescript ts-node @openzeppelin/contracts @matterlabs/zksync-contracts @nomicfoundation/hardhat-ethers @typechain/ethers-v6 @typechain/hardhat typechain ethers dotenv
```

```bash [yarn]
yarn add -D typescript ts-node @openzeppelin/contracts @matterlabs/zksync-contracts @nomicfoundation/hardhat-ethers @typechain/ethers-v6 @typechain/hardhat typechain ethers
yarn add -D typescript ts-node @openzeppelin/contracts @matterlabs/zksync-contracts @nomicfoundation/hardhat-ethers @typechain/ethers-v6 @typechain/hardhat typechain ethers dotenv
```

::
Expand Down Expand Up @@ -130,68 +130,52 @@ 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.
1. Create the file `L1-Governance/.env` 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.

```json [L1-Governance/sepolia.json]
{
"nodeUrl": "<SEPOLIA NODE URL>",
"deployerPrivateKey": "<YOUR PRIVATE KEY>"
}
```txt [L1-Governance/.env]
NODE_RPC_URL=
PRIVATE_KEY=
```

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

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

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

const config: HardhatUserConfig = {
solidity: {
version: "0.8.20",
},
solidity: "0.8.24",
networks: {
// Sepolia network
sepolia: {
url: sepolia.nodeUrl,
accounts: [sepolia.deployerPrivateKey],
},
},
// Sepolia network
sepolia: {
url: process.env.NODE_RPC_URL,
accounts: [process.env.PRIVATE_KEY as any],
},
},
};

export default config;
```

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

```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";
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
async function main() {
// We get the contract to deploy
const Governance = await ethers.getContractFactory("Governance");
const GovernanceModule = buildModule("GovernanceModule", (m) => {
const governance = m.contract("Governance", [], { });
const contract = await Governance.deploy();
const receipt = await contract.deploymentTransaction()?.wait();
return { governance };
});
console.log(`Governance contract was successfully deployed at ${receipt?.contractAddress}`);
}
export default GovernanceModule;
// We recommend always using this async/await pattern to properly handle errors.
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
```

1. From the `L1-governance` folder root, compile and deploy the contract:
Expand All @@ -203,23 +187,31 @@ contract Governance {
npx hardhat compile
# deploy contract
npx hardhat run --network sepolia ./scripts/deploy.ts
npx hardhat ignition deploy ./ignition/modules/Governance.ts --network sepolia
```

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

::

You should see the following output:

```sh
Governance contract was successfully deployed at 0xf28Df77fa8ff56cA3084bd11c1CAF5033A7b8C4A
Deploying [ GovernanceModule ]
Batch #1
Executed GovernanceModule#Governance
[ GovernanceModule ] successfully deployed 🚀
Deployed Addresses
GovernanceModule#Governance - 0xA7d27A1202bE1237919Cf2cb60970141100725b4
```

Save the address to use in a later step.
Loading

0 comments on commit cb3d5ee

Please sign in to comment.