Skip to content

Commit 2b7b097

Browse files
fix: custom zk chain scripts (#148)
fixes for zk chain tutorial: - replace `getWallets` method - use `rich-accounts` method instead of `zksync-cli` - enable EVM interpreter - small clarifications
1 parent 5855aa1 commit 2b7b097

5 files changed

Lines changed: 30 additions & 28 deletions

File tree

code/custom-zk-chain/scripts/depositBaseToken.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
import { ethers } from 'hardhat';
1+
import { ethers, network } from 'hardhat';
2+
import { Wallet, Provider } from 'zksync-ethers';
23

34
async function main() {
4-
const [wallet] = await ethers.getWallets();
5+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6+
const config = network.config as any;
7+
const l1Provider = new Provider(config.ethNetwork);
8+
const l2Provider = new Provider(config.url);
9+
const wallet = new Wallet(process.env.WALLET_PRIVATE_KEY!, l2Provider, l1Provider);
510
const initialBalance = await wallet.getBalance();
611
console.log('INITIAL L2 Base Token Balance 🎉:', ethers.formatEther(initialBalance));
712

code/custom-zk-chain/scripts/depositETH.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
import { ethers } from 'hardhat';
2-
import { utils } from 'zksync-ethers';
1+
import { ethers, network } from 'hardhat';
2+
import { utils, Wallet, Provider } from 'zksync-ethers';
33

44
async function main() {
5-
const [wallet] = await ethers.getWallets();
5+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6+
const config = network.config as any;
7+
const l1Provider = new Provider(config.ethNetwork);
8+
const l2Provider = new Provider(config.url);
9+
const wallet = new Wallet(process.env.WALLET_PRIVATE_KEY!, l2Provider, l1Provider);
610
const l2ETHAddress = await wallet.l2TokenAddress(utils.ETH_ADDRESS_IN_CONTRACTS);
711
console.log('L2 ETH Address:', l2ETHAddress);
812

content/tutorials/custom-zk-chain/10.index.md

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,7 @@ If you choose different names for your ecosystem or chain, remember to update th
9898
│ Eth
9999
100100
◇ Enable EVM emulator?
101-
│ No
102-
103-
◇ Enable EVM emulator?
104-
│ No
101+
│ Yes
105102
106103
◇ Do you want to start containers after creating the ecosystem?
107104
│ Yes
@@ -127,7 +124,7 @@ By running this command and selecting these options, you just:
127124
You can read more about data availability options for ZKsync Chains in the
128125
[ZKsync Chains](https://docs.zksync.io/zk-stack/concepts/zk-chains#data-availability-da) docs.
129126
- Selected ETH to use as the base token.
130-
- Selected to not use the EVM Emulator.
127+
- Selected to enable the EVM Emulator, which allows EVM bytecode to be deployed.
131128
- Started the containers for the ecosystem in Docker.
132129

133130
Inside the generated `my_elastic_network` folder, you should now have the following contents:
@@ -225,7 +222,8 @@ The [Portal](https://github.com/matter-labs/dapp-portal) module is a web app tha
225222
- View balances.
226223
- Add contacts for quick and easy access.
227224
228-
Once you have at least one chain initialized, you can run the portal app locally:
225+
Once you have at least one chain initialized, you can run the portal app locally.
226+
Open a new terminal in your ecosystem folder and run:
229227
230228
```bash
231229
zkstack portal
@@ -242,25 +240,29 @@ You can now navigate to the portal web app. By default, the portal frontend star
242240
A block explorer is a web-app that lets you view and inspect transactions, blocks,
243241
contracts and more. A [free open source block explorer](https://github.com/matter-labs/block-explorer) is available for your ZKsync Chain.
244242
245-
First, each chain should be initialized:
243+
First, each chain should be initialized.
244+
To initialize your chain,
245+
open a new terminal in your ecosystem folder and run:
246246
247247
```bash
248248
zkstack explorer init
249249
```
250250
251+
You can select the default options for the prompts.
251252
This command creates a database to store explorer data and generates a docker compose file with explorer services
252253
(`explorer-docker-compose.yml`).
253254
254255
Next, for each chain you want to have an explorer, you need to start its backend services:
255256
256257
```bash
257-
zkstack explorer backend --chain <chain_name>
258+
zkstack explorer backend --chain zk_chain_1
258259
```
259260
260261
This command uses the previously created docker compose file to start the services (api, data fetcher, worker) required for
261262
the explorer.
262263
263-
Finally, you can run the explorer app:
264+
Finally, you can run the explorer app.
265+
Open another terminal in your ecosystem folder and run:
264266
265267
```bash
266268
zkstack explorer run
@@ -283,20 +285,13 @@ You can find a full list of rich wallet addresses and their private keys in the
283285
Never use these wallets in production or send real funds to them.
284286
::
285287
286-
Open a new terminal and run the command below to bridge some ETH to `zk_chain_1` using ZKsync CLI:
288+
Open a new terminal in your ecosystem folder and run the command below to bridge some ETH to `zk_chain_1`.
289+
This command will bridge 1 ETH to `0x36615cf349d7f6344891b1e7ca7c72883f5dc049`.
287290
288291
:test-action{actionId="deposit-eth"}
289292
290293
```bash
291-
npx zksync-cli bridge deposit --rpc=http://localhost:3050 --l1-rpc=http://localhost:8545
292-
```
293-
294-
For testing purposes, we'll use one of the rich wallets as both the sender and recipient:
295-
296-
```shell
297-
? Amount to deposit 10
298-
? Private key of the sender 0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110
299-
? Recipient address on L2 0x36615Cf349d7F6344891B1e7CA7C72883F5dc049
294+
zkstack dev rich-account --chain zk_chain_1
300295
```
301296
302297
To see that it worked, let's check the balance of that address on `zk_chain_1`:

content/tutorials/custom-zk-chain/20.customizing-your-chain.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ you can add the `WALLET_PRIVATE_KEY` environment variable:
117117
:test-action{actionId="new-env"}
118118

119119
```bash
120-
# Use the private key of the `governor` from configs/wallets.yaml
120+
# Use the private key of the `governor` from my_elastic_network/configs/wallets.yaml
121121
WALLET_PRIVATE_KEY=<governor_private_key_from_configs_wallets.yaml>
122122
```
123123

@@ -263,7 +263,7 @@ This time, use the answers below:
263263
│ 1
264264
265265
◇ Enable EVM emulator?
266-
No
266+
Yes
267267
268268
◇ Set this chain as default?
269269
│ Yes

tests/configs/custom-zk-chain.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ const partOneSteps: IStepConfig = {
4646
'deposit-eth': {
4747
action: 'runCommand',
4848
commandFolder: 'tests-output/custom-zk-chain/my_elastic_network',
49-
prompts:
50-
'Amount to deposit:9|Private key of the sender:0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110|Recipient address on L2:',
5149
},
5250
'check-balance': {
5351
action: 'runCommand',

0 commit comments

Comments
 (0)