Skip to content

Commit

Permalink
fix: cross-chain governance (#32)
Browse files Browse the repository at this point in the history
* fix: broken tutorial

* fix: md lint
  • Loading branch information
uF4No authored Jul 22, 2024
1 parent 34ad66e commit c8352df
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 285 deletions.
85 changes: 39 additions & 46 deletions content/tutorials/cross-chain-governance/10.index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ description: Build and deploy a smart contract in L1 and send transactions that
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
Expand Down Expand Up @@ -52,7 +53,7 @@ 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.
Expand All @@ -73,11 +74,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 +131,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 +188,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 c8352df

Please sign in to comment.