Skip to content

Commit

Permalink
docs: edit zksync-101 (#181)
Browse files Browse the repository at this point in the history
# Description

This PR updates the ZKsync 101 guide with an up to date project template
that focuses on using ZKsync CLI and in-memory node for local
development.

It still uses the same smart contracts and focus, but streamlines it so
that only one template is downloaded to use for the entire series.

This will use the templates from
matter-labs/zksync-contract-templates#22
  • Loading branch information
itsacoyote authored Aug 23, 2024
1 parent 86f913a commit 365c5ea
Show file tree
Hide file tree
Showing 26 changed files with 1,196 additions and 2,935 deletions.
130 changes: 63 additions & 67 deletions content/00.build/05.start-coding/10.zksync-101/00.index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,113 +11,109 @@ help you become a great developer on ZKsync! You will learn how to:

:check-icon Initialize a new project with ZKsync CLI.

:check-icon Deploy contracts on ZKsync Era using Hardhat or Foundry.
:check-icon Deploy contracts on ZKsync Era using Hardhat.

:check-icon Test your contracts with Hardhat or Foundry.
:check-icon Test your contracts with Hardhat.

:check-icon Implement upgradable patterns for your contracts.

:check-icon Implement a Paymaster to simplify transactions for your users.

---

## Install zksync-cli
## Install ZKsync CLI

Our Quickstart series utilizes ZKsync CLI to help you develop and interact with ZKsync from your local machine.
We will use the full features of ZKsync CLI to build and deploy contracts in a local ZKsync Era test node.
Follow the instructions to install all dependencies including the optional dependencies
and install ZKsync CLI globally on the [Getting started](/build/zksync-cli) page.
Our 101 series utilizes ZKsync CLI to help you develop and interact with ZKsync from your local machine.
We will use the full features of ZKsync CLI to build and deploy contracts in a local ZKsync Era node.

### Setup local node
### Prerequisites

This series of guides will use ZKsync Era test node which allows for quicker testing and debugging processes.
A great benefit of using a local test node is that you will avoid incurring any actual transaction costs.
ZKsync Era test node provides a set of rich wallets that come with more than enough ETH to use for development.
- [Node.js v18 or newer](https://nodejs.org/en)
- [Docker Desktop](https://www.docker.com/products/docker-desktop/)
- [Git](https://docs.github.com/en/get-started/getting-started-with-git/set-up-git)

#### Run a local in memory node

Once you've followed all of the instructions on [Getting started](/build/zksync-cli) to setup ZKsync CLI on your machine,
check and ensure that Docker is running. The easiest way to start Docker is to open the Docker Desktop app.

We are going to use the "In memory node" module for our local node setup.

Run the following command in your terminal:
Open a terminal and install ZKsync CLI with the following command:

```bash
zksync-cli dev config
npm install -g zksync-cli
```

It will provide a list of available node types you can run locally.
## Setup local node

Use the arrow keys to navigate to "In memory node" and press **Enter** to select.
The next question will ask what additional modules you want to use.
Make sure additional modules are unselected for this setup and press **Enter** to finish the configuration.
This series of guides will use an in memory node which allows for quicker testing and debugging processes.
A great benefit of using a local node is that you will avoid incurring any actual transaction costs.
ZKsync Era node provides a set of rich wallets that come with more than enough ETH to use for development.

The In memory node module will run a lighter version of the ZKsync Era node
which is ideal for swift testing, prototyping, and bootloader and system contract testing.
### Run a local in memory node

Run the following command in your terminal to start up the node:
To run a local in memory node on your machine, you will need Docker running.
The easiest way to start Docker is to run the Docker Desktop app.

```bash
zksync-cli dev start
```
We are going to use the "In memory node" module for our local node setup.

The local era node will also include pre-configured rich wallets for use, visit [era-test-node rich wallets](/build/test-and-debug/in-memory-node#pre-configured-rich-wallets).
1. Run the following command in your terminal:

Your local ZKsync Era node is accessible at **[http://127.0.0.1:8011](http://127.0.0.1:8011/)**, ready for deployment or testing purposes.
You can use the Docker Desktop app to view logs from the running ZKsync Era node or use the `zksync-cli dev logs` command.
When you are done running your local ZKsync Era node, you can stop it with `zksync-cli dev stop`.
You can learn more about managing a local node with ZKsync CLI on [Running a node](/build/zksync-cli/running-a-node).
```bash
zksync-cli dev config
```

---
It will provide a list of available node types you can run locally.

## Choose Hardhat or Foundry
2. Use the arrow keys to navigate to "In memory node" and press **Enter** to select.
The next question will ask what additional modules you want to use.
Make sure additional modules are unselected for this setup and press **Enter** to finish the configuration.

Our Quickstart series provides two options for your learning process using
either Hardhat or Foundry. Pick one to use and stick with as you go through
each of the guides.
```bash
? Node to use (Use arrow keys)
❯ In memory node - Quick startup, no persisted state, only L2 node - zkcli-in-memory-node
Dockerized node - Persistent state, includes L1 and L2 nodes - zkcli-dockerized-node
(Move up and down to reveal more choices)
```

<!-- Create a component that sets which tool they use and pre-set the tabs -->
The in memory node module will run a lighter version of the ZKsync Era node
which is ideal for swift testing, prototyping, bootloader and system contract testing.

### Install foundry-zksync
3. Run the following command in your terminal to start up the node:

If you choose to use Foundry for the Quick Start series, you will need to
install the `foundry-zksync` tool. This tool is a specialized fork of Foundry, tailored for ZKsync.
It extends Foundry's capabilities for Ethereum app development to support ZKsync,
allowing for the compilation, deployment, testing, and interaction with smart contracts on ZKsync.
```bash
zksync-cli dev start
```

::callout{icon="i-heroicons-information-circle-16-solid" color="amber"}
`foundry-zksync` is still in an alpha stage, so some features might not be fully supported
yet and may not work as fully intended. It is open-sourced and contributions are welcome.
::
The in memory node includes pre-configured rich wallets for use, see [in-memory-node rich wallets](/build/test-and-debug/in-memory-node#pre-configured-rich-wallets).

Your in memory node is accessible at **[http://127.0.0.1:8011](http://127.0.0.1:8011/)**, ready for deployment or testing purposes.
You can use the Docker Desktop app to view logs from the running ZKsync Era node or use the `zksync-cli dev logs` command.
When you are done running your in memory node, you can stop it with `zksync-cli dev stop`.
You can learn more about managing a local node with ZKsync CLI on [Running a node](/build/zksync-cli/running-a-node).

Quickly set up `foundry-zksync` by following these steps:
## Create the ZKsync 101 project

1. **Clone the Repository**:
Download the latest version from GitHub:
We have a template available for you to get started with quickly in the ZKsync 101 series.
In a directory where you want to create your project, run the following command in your terminal:

```bash
git clone [email protected]:matter-labs/foundry-zksync.git
cd foundry-zksync
```
```sh
zksync-cli create zksync-101 --template zksync-101
```

2. **Run the Installer**:
Execute the script to install the `foundry-zksync` binaries `forge` and `cast`:
After you run the `create` command, the CLI will download and install packages for the project.
You should see a success message and instructions to get started with your project.

```bash
./install-foundry-zksync
```
Since we are using a local in memory node for development, we can use one of the
rich wallets for transactions and deployments.

### Private key setup with Foundry keystore
Rename the `.env.example` to `.env` which includes the private key for the first rich wallet.

:display-partial{ path="_partials/_foundry-create-keystore" }
::callout{icon="i-heroicons-exclamation-triangle" color="amber"}
Never save a real private key to the `.env` file!
::

---

## Next Steps

You should now have a fully working local environment to build new projects on ZKsync!

- Continue to [Hello ZKsync!](/build/start-coding/zksync-101/hello-zksync) to begin the series on building a crowdfunding campaign for Zeek.
- This setup provides you everything you need to build in ZKsync.
- You can skip on to [creating your own projects using ZKsync CLI](/build/zksync-cli/creating-projects).
- Continue to the next step, [Hello ZKsync!](/build/start-coding/zksync-101/hello-zksync) to begin the 101 series
on building a crowdfunding campaign for Zeek.
- This setup provides you everything you need to build on ZKsync Era.
- You can skip this 101 series to go on to [creating your own projects using ZKsync CLI](/build/zksync-cli/creating-projects).
Loading

0 comments on commit 365c5ea

Please sign in to comment.