Skip to content

Commit

Permalink
docs: address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahschwartz committed Aug 13, 2024
1 parent faba02e commit 38bee25
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 50 deletions.
26 changes: 7 additions & 19 deletions content/tutorials/custom-zk-chain/10.index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ description: Create and run your first ZK chain.
This tutorial shows you how to use the `zk_inception` CLI to run an Elastic Chain ecosystem and custom ZK chain locally:

- You'll set up a local **Elastic Chain ecosystem**
- You'll create a standard **ZK chain** and deploy a smart contract to it
- You'll create a second ZK chain that uses a **custom ERC20 base token**
- You'll create a standard **ZK chain**
- You'll deploy a smart contract to your local **ZK chain**
- You'll create a second ZK chain that uses a **custom ERC20 base token**

## Prerequisites

Expand Down Expand Up @@ -149,21 +150,7 @@ Next, run the `init` command below to deploy the ecosystem:
zk_inception ecosystem init --dev
```

The `--dev` flag will choose the default options for development. Using this flag is equivalent to answering the prompts like this:

```bash
◇ Do you want to deploy Paymaster contract?
│ Yes
◇ Do you want to deploy some test ERC20s?
│ Yes
◇ Do you want to deploy ecosystem contracts? (Not needed if you already have an existing one)
│ Yes
◆ What is the RPC URL of the L1 network?
│ http://localhost:8545 (default)
```
The `--dev` flag will choose the default options for development.

::callout{icon="i-heroicons-light-bulb"}
If you have any issues at this step, try reinstalling the dependencies at the top.
Expand All @@ -178,7 +165,7 @@ To summarize, the `init` command:
- Compiles and deploys all of the necessary contracts for the ecosystem.
- Deploys `zk_chain_1` to the ecosystem.
- Sets up a database for the default chain (in this case `zk_chain_1`).
- Deploys a paymaster contract and some test ERC20 contracts (if selected) to use for development.
- Deploys a paymaster contract and some test ERC20 contracts to use for development.

You can find the paymaster contract deployed to your chain in the `zksync-era` repo in `contracts/l2-contracts/contracts/TestnetPaymaster.sol`,
and the deployed address inside `my_elastic_chain/chains/zk_chain_1/configs/contracts.yaml` at `l2:testnet_paymaster_addr`.
Expand Down Expand Up @@ -268,7 +255,8 @@ Use the same private key for the rich wallet:
0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110
```

In the `hardhat.config.ts` file, change the default network on line 6 to `dockerizedNode`:
In the `hardhat.config.ts` file, change the default network on line 6 to `dockerizedNode`,
which is already configured to connect to the local chain node running on port `3050`:

```bash
defaultNetwork: "dockerizedNode",
Expand Down
79 changes: 48 additions & 31 deletions content/tutorials/custom-zk-chain/20.customizing-your-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ For now, you have the ability to add any tokens to the allowlist in your local e
The overall flow for setting up a local chain with a custom ERC20 base token looks like this:

1. Deploy an ERC20 token to the L1.
1. Send ERC20 tokens to the ecosystem and chain governor addresses on the L1.
1. Create your new chain that uses the ERC20 token and set it as the default.
1. Send ERC20 tokens to the ecosystem and chain governor addresses on the L1.
1. Initialize the new chain in the ecosystem.
1. Bridge tokens from the L1 to your new chain.

## Deploying an ERC20 token

For the first step of this flow, let's make a new hardhat project.

### Setup

Move out of your previous folder and make a new folder for the ERC20 token contract.

```bash
Expand Down Expand Up @@ -54,6 +56,8 @@ yarn add -D typescript ts-node @openzeppelin/contracts @nomicfoundation/hardhat-

::

### Configuring Hardhat

Once installed, replace your existing config in `hardhat.config.ts` with the config below:

```ts
Expand All @@ -76,20 +80,26 @@ const config: HardhatUserConfig = {
export default config;
```

Now hardhat is configured to connect to our local reth node (the L1) running at local port `8545`.
For the inital release of the ZK stack, we have to deploy the token to the L1 and bridge to our chain later.
However, in the future this may change.

Next, create a `.env` file with:

```bash
touch .env
```

and add the `WALLET_PRIVATE_KEY` environment variable with the private key of the rich wallet we've been using
Add the `WALLET_PRIVATE_KEY` environment variable with the private key of the rich wallet we've been using
so that we can deploy using a pre-funded address:

```env
WALLET_PRIVATE_KEY=0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110
```

Now that we've configured hardhat, let's add the contract and deploy script.
### Deploying an ERC20 Contract

Now that we've configured hardhat and the deployer wallet, let's add the contract and deploy script.
Rename the example generated contract file to `CustomBaseToken.sol`:

```bash
Expand Down Expand Up @@ -117,7 +127,7 @@ contract CustomBaseToken is ERC20, Ownable, ERC20Burnable {
}
```

Next, let's update the ignition module.
Next, let's update the ignition module to deploy the ERC20 contract.
Rename the module file with the command below:

```bash
Expand All @@ -141,7 +151,7 @@ const CustomBaseTokenModule = buildModule("CustomBaseTokenModule", (m) => {
export default CustomBaseTokenModule;
```

To deploy the token contract, run:
To run the module and deploy the token contract, run:

```bash
npx hardhat ignition deploy ./ignition/modules/CustomBaseToken.ts --network localRethNode
Expand All @@ -157,32 +167,9 @@ cast balance --erc20 <0xYOUR_TOKEN_ADDRESS> 0x36615Cf349d7F6344891B1e7CA7C72883F
--rpc-url http://localhost:8545
```

Now that you have some tokens, the next step is to send some to each of the governor's addresses for the ecosystem and chain on the L1.
This will allow you to register and deploy your chain, and deploy the paymaster.
You can find the address for the ecosystem governor in `my_elastic_chain/configs/wallets.yaml` under `governor`.
The chain governor address can be found in `my_elastic_chain/chains/custom_zk_chain/configs/wallets.yaml` under `governor`.

Run the command below to use `cast` to transfer some of your ERC20 tokens to the governor's address on the L1.

```bash
cast send <0xYOUR_TOKEN_ADDRESS> "transfer(address,uint256)" \
<0x_YOUR_GOVERNOR_ADDRESS> 1000000000000000000 \
--private-key 0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110 \
--rpc-url http://localhost:8545 \
--gas-price 30000000000
```

To verify that this worked, check the balance of the governor's address:

```bash
cast balance --erc20 <0xYOUR_TOKEN_ADDRESS> \
<0x_YOUR_GOVERNOR_ADDRESS> \
--rpc-url http://localhost:8545
```

## Creating a new chain

Now that your ERC20 token is deployed and the governor addresses are funded with that token, you can create a new chain.
Now that your ERC20 token is deployed, you can create a new chain.

First, shut down the node server running for `zk_chain_1`.

Expand Down Expand Up @@ -235,10 +222,40 @@ For example, if we set the nominator to 20 and the denominator to 1, together th
this would mean that 20 tokens would be given the equivalent value as 1 ETH for gas.
For testing purposes, we'll just use a 1:1 ratio.

Next, initialize the chain in the ecosystem with:
### Funding the governor addresses

Now that you have some tokens and created a new chain,
the next step is to send some to each of the governor's addresses for the ecosystem and chain on the L1.
This will allow you to register and deploy your chain, and deploy the paymaster.
For the _ecosystem governor_, you can find the address in `my_elastic_chain/configs/wallets.yaml` under `governor`.
The second governor address you need to fund is for the _chain governor_.
The chain governor address can be found in `my_elastic_chain/chains/custom_zk_chain/configs/wallets.yaml` also under `governor`.
Run the command below **twice** (once for each governor address) to use `cast` to transfer some of your ERC20 tokens to the governor's address on the L1.

```bash
cast send <0xYOUR_TOKEN_ADDRESS> "transfer(address,uint256)" \
<0x_YOUR_GOVERNOR_ADDRESS> 1000000000000000000 \
--private-key 0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110 \
--rpc-url http://localhost:8545 \
--gas-price 30000000000
```

To verify that this worked, check the balance of both governor addresses:

```bash
cast balance --erc20 <0xYOUR_TOKEN_ADDRESS> \
<0x_YOUR_GOVERNOR_ADDRESS> \
--rpc-url http://localhost:8545
```

### Initializing the chain

Next, initialize the chain in the ecosystem with the command below, and select the default options for the prompts.

```bash
zk_inception chain init --dev
zk_inception chain init
```

Now that the chain is initialized, you can start the chain server:
Expand Down

0 comments on commit 38bee25

Please sign in to comment.