Skip to content

Commit

Permalink
docs: Zksync 101 refactor (#170)
Browse files Browse the repository at this point in the history
# Description

Update ZKsync 101 to use zksync-cli and inMemoryNode for tutorials.
  • Loading branch information
itsacoyote authored Aug 5, 2024
1 parent ebbe26b commit 4c4c03c
Show file tree
Hide file tree
Showing 20 changed files with 247 additions and 477 deletions.
Binary file modified bun.lockb
Binary file not shown.
76 changes: 29 additions & 47 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 @@ -9,7 +9,7 @@ In this guide, we'll walk you through the process of creating and deploying a si
By the end of the series, you will learn integral pieces that will
help you become a great developer on ZKsync! You will learn how to:

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

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

Expand All @@ -23,52 +23,51 @@ help you become a great developer on ZKsync! You will learn how to:

## Install zksync-cli

Our Quickstart series utilizes the `zksync-cli` to help you develop and interact with ZKsync from your local machine. Check out our
[zksync-cli section](/build/zksync-cli) to learn more on how to use the 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.

You will need to install a couple tools to effectively use `zksync-cli`:
### Setup local node

#### Install Node.js or Bun.sh
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.

You will need either Node.js or Bun.sh.
The choice depends on your project's requirements and personal preference for package management and execution speed.
If you are unfamiliar with both, choose Node.js.
#### Run a local in memory node

- Node.js
- Download the Long-Term Support (LTS) version from the [official Node.js website](https://nodejs.org/en/download).
- For first-time users, the [Node.js usage guide](https://nodejs.org/api/synopsis.html#usage)
offers comprehensive instructions on getting started.
- Bun.sh
- Obtain the latest version from the [Bun installation page](https://bun.sh/docs/installation).
Bun.sh is known for its high performance and modern JavaScript features.
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.

### Setup era local node (optional)
We are going to use the "In memory node" module for our local node setup.

Our Quickstart series will have you compile and deploy contracts to
%%zk_testnet_name%% which requires you to have ETH in your wallet for funding transactions.
Alternatively, our `zksync-cli` tool provides a way for you to setup a test node locally.
This era local node allows for quicker testing and debugging processes without incurring testnet transaction costs.
Run the following command in your terminal:

#### Install Docker
```bash
zksync-cli dev config
```

The era local node will need Docker to run locally on your machine.
Download the appropriate version from the [Docker website](https://docs.docker.com/engine/install/).
It will provide a list of available node types you can run locally.

#### Run a local ZKsync Era 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.

Run the following command in your terminal:
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 the following command in your terminal to start up the node:

```bash
zksync-cli dev start
```

Choose "In memory node" to deploy a local ZKsync Era node in a Docker container.

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).

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.
Leave this terminal open and running as you build your projects.
When you are done running your local Era node, you can stop it with `Ctrl+C`.
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).

---

Expand Down Expand Up @@ -115,27 +114,10 @@ Quickly set up `foundry-zksync` by following these steps:

---

## Fund your wallet

If you did not set up a local era node for development and plan to use %%zk_testnet_name%%, you will need testnet ETH to fund transactions.

1. Obtaining Testnet ETH:

- Use the [LearnWeb3 faucet](https://learnweb3.io/faucets/zksync_sepolia/)
to directly receive testnet ETH on %%zk_testnet_name%%.
- Alternatively, acquire SepoliaETH from [recommended faucets](/ecosystem/network-faucets)
transfer it to the %%zk_testnet_name%% via the [ZKsync bridge](https://portal.zksync.io/bridge/?network=sepolia).

2. Verify your balance:

- Check your wallet's balance using the [%%zk_testnet_name%% explorer](%%zk_testnet_block_explorer_url%%).

---

## 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` with your fully set up local dev environment.
- You can skip on to [creating your own projects using ZKsync CLI](/build/zksync-cli/creating-projects).
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ This series requires some initial setup of tools to elevate your
development experience building for ZKsync.
Make sure to go through the setup provided in the initial [Getting started](/build/start-coding/zksync-101) section.

Select the framework you want to get started using ZKsync Era with.
If you have not started up a local node yet from the Getting started page, see
[Set up your local node](/build/start-coding/zksync-101#setup-local-node) in Getting started.

Select the following framework you want to get started using ZKsync Era with.

::content-switcher
---
Expand All @@ -49,8 +52,8 @@ Having successfully deployed your first contract on ZKsync, you're well on your
a proficient ZKsync developer. To expand your expertise:

- **Explore Contract Factories:** Enhance your project by building a contract factory
for the `CrowdfundingCampaign` contract in the [next guide](/build/start-coding/zksync-101/contract-factory). This will allow you to efficiently
manage multiple crowdfunding campaigns, each with its own unique parameters.
for the `CrowdfundingCampaign` contract in the [next guide](/build/start-coding/zksync-101/contract-factory).
This will allow you to efficiently manage multiple crowdfunding campaigns, each with its own unique parameters.
- **Dive Deeper into ZKsync Features:** Investigate advanced ZKsync features such as account abstraction,
and paymasters.
- **Join the Community:** Engage with the ZKsync developer community through forums,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ numerous similar contracts efficiently.

## Setup the project

::callout{icon="i-heroicons-information-circle" color="blue"}
If you have not started up a local node yet from the Getting started page, run `zksync-cli dev start`.
Make sure you are running the "In memory node" option.
::

Select the framework you want to get started using ZKsync Era with.

::content-switcher
Expand Down
5 changes: 5 additions & 0 deletions content/00.build/05.start-coding/10.zksync-101/30.testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ Dive into the world of smart contract testing and solidify the foundation of you

## Setup the project

::callout{icon="i-heroicons-information-circle" color="blue"}
If you have not started up a local node yet from the Getting started page, run `zksync-cli dev start`.
Make sure you are running the "In memory node" option.
::

::content-switcher
---
items: [{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ lead you through the strategies and practices for making the `CrowdfundingCampai
Begin to understand smart contract evolution and empower your ZKsync applications with the
flexibility of upgradability.

::callout{icon="i-heroicons-information-circle" color="blue"}
If you have not started up a local node yet from the Getting started page, run `zksync-cli dev start`.
Make sure you are running the "In memory node" option.
::

Select your preferred upgrade mechanism:

::content-switcher
Expand Down
15 changes: 8 additions & 7 deletions content/00.build/05.start-coding/10.zksync-101/50.paymaster.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,12 @@ interactions. This feature enhances user engagement and adoption of dApps.
## Next Steps

- **Experiment with Different Paymaster Contracts:** Now that you are familiar with both approval-based and general
paymaster flows, you can experiment with these contracts by deploying them under various conditions
and with different types validations, restrictions and enhancements.
- **Develop a Front-End Interface:** Consider building a user interface that interacts with the paymaster contracts
you have deployed. This will not only improve the usability of your contracts but also provide practical insights
into how end-users interact with your dApps in real-world scenarios.
paymaster flows, you can experiment with these contracts by deploying them under various conditions
and with different types validations, restrictions and enhancements.
- **Develop a Front-End Interface:** Consider
[building a user interface with ZKsync CLI](/build/zksync-cli/creating-projects) that interacts with the paymaster contracts
you have deployed. This will not only improve the usability of your contracts but also provide practical insights
into how end-users interact with your dApps in real-world scenarios.
- **Community Engagement and Contribution:** Join the vibrant ZKsync community.
Participate in forums, Discord, or GitHub discussions. Sharing insights, asking queries,
and contributing can enrich the ecosystem and your understanding of ZKsync.
Participate in forums, Discord, or GitHub discussions. Sharing insights, asking queries,
and contributing can enrich the ecosystem and your understanding of ZKsync.
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,10 @@ title: Foundry | Deploy Contract Factory
Run the following command in your terminal to initialize the Foundry project.

```sh
npx zksync-cli@latest create --template qs-fs-factories foundry-contract-factory-quickstart
zksync-cli create --template qs-fs-factories foundry-contract-factory-quickstart
cd foundry-contract-factory-quickstart
```

## Set up your wallet

:display-partial{path="build/start-coding/zksync-101/_partials/_setup-wallet"}

---

## Review the CrowdfundingFactory contract

The `CrowdfundingFactory.sol` we will compile and deploy is provided under the [`/src` directory](https://github.com/matter-labs/zksync-contract-templates/blob/main/templates/quickstart/foundry/factory/src/CrowdfundFactory.sol).
Expand Down Expand Up @@ -105,9 +99,7 @@ our new `CrowdfundingFactory`.
command:

```bash
forge create src/CrowdfundFactory.sol:CrowdfundingFactory --account myKeystore --rpc-url zkSyncSepoliaTestnet --chain %%zk_testnet_chain_id%% --zksync
# To deploy the contract on local in-memory node:
# forge script script/DeployFactory.s.sol:DeployFactoryAndCreateCampaign --account myKeystore --sender <KEYSTORE_ADDRESS> --rpc-url inMemoryNode --broadcast --zksync
forge create src/CrowdfundFactory.sol:CrowdfundingFactory --account myKeystore --rpc-url inMemoryNode --zksync
```

Upon a successfull deployment you'll receive details of the deploying address, the contract address,
Expand All @@ -122,9 +114,7 @@ command:
1. Using the `CrowdfundingFactory` contract address let's deploy our `CrowdfundingCampaign`:

```bash
cast send 0x607545Fd35ef49d7445555ddFa22938fD4Efb219 "createCampaign(uint256)" "1" --rpc-url zkSyncSepoliaTestnet --chain %%zk_testnet_chain_id%% --account myKeystore
# To use the contract factory on local in-memory node:
# cast send 0x607545Fd35ef49d7445555ddFa22938fD4Efb219 "createCampaign(uint256)" "1" --rpc-url inMemoryNode --chain 260 --account myKeystore --sender <KEYSTORE_ADDRESS>
cast send 0x607545Fd35ef49d7445555ddFa22938fD4Efb219 "createCampaign(uint256)" "1" --rpc-url inMemoryNode --account myKeystore
```

Upon a successfull deployment you'll receive details of the transaction, including the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,23 @@ title: Hardhat | Deploy Contract Factory
Run the following command in your terminal to initialize the project.

```sh
npx zksync-cli@latest create --template qs-factories contract-factory-quickstart
zksync-cli create --template qs-factories contract-factory-quickstart
cd contract-factory-quickstart
```

## Set up your wallet
## Update the hardhat.config.ts

:display-partial{path="build/start-coding/zksync-101/_partials/_setup-wallet"}
Since we are using the "In memory node" with ZKsync CLI, we need to set the default network Hardhat uses
for deploying.

---
Open up the `hardhat.config.ts` file and set the `defaultNetwork` to `inMemoryNode`.

```ts
// ...
const config: HardhatUserConfig = {
defaultNetwork: "inMemoryNode",
// ...
```
## Compile the contracts
Expand Down Expand Up @@ -134,38 +142,12 @@ The deployment script is located at `/deploy/deployUsingFactory.ts`.
- The `createCampaign` method is called on this instance to create
and deploy a new crowdfunding campaign contract.
Run the deployment command. The default command
deploys to the configured network in your Hardhat setup. For local deployment, append
`--network inMemoryNode` to deploy to the local in-memory node running.

::code-group
Run the deployment command.
```bash [npm]
npx hardhat deploy-zksync --script deployUsingFactory.ts
# To deploy the contract on local in-memory node:
# npx hardhat deploy-zksync --script deployUsingFactory.ts --network inMemoryNode
```

```bash [yarn]
yarn hardhat deploy-zksync --script deployUsingFactory.ts
# To deploy the contract on local in-memory node:
# yarn hardhat deploy-zksync --script deployUsingFactory.ts --network inMemoryNode
npm run deploy
```
```bash [pnpm]
pnpx exec hardhat deploy-zksync --script deployUsingFactory.ts
# To deploy the contract on local in-memory node:
# pnpx exec hardhat deploy-zksync --script deployUsingFactory.ts --network inMemoryNode
```

```bash [bun]
bun run hardhat deploy-zksync --script deployUsingFactory.ts
# To deploy the contract on local in-memory node:
# bun run hardhat deploy-zksync --script deployUsingFactory.ts --network inMemoryNode
```

::

Upon successful deployment, you'll receive output detailing the deployment process,
including the contract address, source, and encoded constructor arguments:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ title: Foundry | Deploy Contract
Run the following command in your terminal to initialize the Foundry project.

```sh
npx zksync-cli@latest create --template qs-fs-hello-zksync hello-zksync-foundry-quickstart
zksync-cli create --template qs-fs-hello-zksync hello-zksync-foundry-quickstart
cd hello-zksync-foundry-quickstart
```

Expand Down Expand Up @@ -142,9 +142,7 @@ the transaction broadcast and `vm.stopBroadcast()` to end it, facilitating the a
Execute the deployment command.

```bash
forge script script/Deploy.s.sol:DeployCrowdfundContract --account myKeystore --sender <KEYSTORE_ADDRESS> --rpc-url zkSyncSepoliaTestnet --broadcast --zksync
# To deploy the contract on local in-memory node:
# forge script script/Deploy.s.sol:DeployCrowdfundContract --account myKeystore --sender <KEYSTORE_ADDRESS> --rpc-url inMemoryNode --broadcast --zksync
forge script script/Deploy.s.sol:DeployCrowdfundContract --account myKeystore --sender <KEYSTORE_ADDRESS> --rpc-url inMemoryNode --broadcast --zksync
```

Upon successful deployment, you'll receive output detailing the deployment process,
Expand Down
Loading

0 comments on commit 4c4c03c

Please sign in to comment.