Getting started

Learn to build and deploy smart contracts on ZKsync Era.

Welcome to ZKsync 101 for deploying smart contracts on ZKsync! In this guide, we'll walk you through the process of creating and deploying a simple smart contract that creates a crowdfunding campaign for Zeek.

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:

Initialize a new project with ZKsync CLI.

Deploy contracts on ZKsync Era using Hardhat.

Test your contracts with Hardhat.

Implement upgradable patterns for your contracts.

Implement a Paymaster to simplify transactions for your users.


Install ZKsync CLI

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.

Prerequisites

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

npm install -g zksync-cli

Setup local node

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.

Run a local in memory 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.

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

  1. Run the following command in your terminal:
    zksync-cli dev config
    

    It will provide a list of available node types you can run locally.
  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.
    ? 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)
    

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

    The in memory node includes pre-configured rich wallets for use, see in-memory-node rich wallets.

Your in memory node is accessible at 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.

Create the ZKsync 101 project

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:

zksync-cli create zksync-101 --template zksync-101

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.

Since we are using a local in memory node for development, we can use one of the rich wallets for transactions and deployments.

Rename the .env.example to .env which includes the private key for the first rich wallet.

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!


Made with ❤️ by the ZKsync Community