Setup

Get setup with ZKsync testnet or a local node

Welcome to the Quickstart!

This section is designed for developers new to ZKsync and gives you the options of deploying to either a local node or a testnet using the most popular smart contract development frameworks.

You will learn how to:

Get setup with either the testnet or a local node.

Build an ERC-20 token contract.

Deploy the smart contract.

Interact with the contract using a script.

Interact with the contract in a simple frontend.

Setup

Choose between using testnet or a local node.

Prerequisites

Before you move onto the next section, make sure that you:

  1. Have a browser wallet extension installed. If you're not sure what wallet to use, try Metamask.
  2. Have configured the ZKsync OS Developer Preview testnet in your wallet.
  3. Have bridged at least 0.05 testnet ETH to your wallet on the ZKsync OS Developer Preview network.

Add ZKsync OS Developer Preview to your MetaMask wallet

You can add ZKsync OS Developer Preview to your MetaMask wallet using the button below:

If you are using a different in-browser wallet, the button above may also work for them.

Manually add ZKsync OS Developer Preview

To manually add ZKsync OS Developer Preview as a custom network in your wallet, follow these steps:

  1. Find the “Add Network” option in your wallet (in MetaMask, you can find this in the networks dropdown).
  2. Click on “Add Network" and "Add network manually".
  3. Fill in the following details for the ZKsync OS Developer Preview testnet:

Network details

PropertyValue
Network Name
ZKsync OS Developer Preview
RPC URL
https://zksync-os-testnet-alpha.zksync.dev/
WebSocket URL
wss://zksync-os-testnet-alpha.zksync.dev/ws
Chain ID
8022833
Currency Symbol
ETH
Block Explorer URL
Explorer Verification API
https://block-explorer-api.zksync-os-testnet-alpha.zksync.dev/api

Get funds for your wallet

Once you have your wallet connected to the ZKsync OS Developer Preview environment, you can bridge testnet ETH from Sepolia Testnet. You can get testnet funds on Sepolia from one of many testnet faucets.

Bridging testnet ETH

The easiest way to bridge funds to the testnet is by using the ZKsync OS Portal to bridge testnet ETH over.

You can also bridge funds in your terminal with cast or in a script using zksync-js as shown in the examples below.

Bridging with cast

export BRIDGEHUB_ADDRESS=0xc4fd2580c3487bba18d63f50301020132342fdbd
export CHAIN_ID=8022833
export SEPOLIA_RPC=<YOUR_SEPOLIA_RPC_ENDPOINT>
export ADDRESS=<YOUR_WALLET_ADDRESS>
export VALUE_TO_BRIDGE=<AMOUNT_TO_BRIDGE_IN_WEI>
cast send -r $SEPOLIA_RPC $BRIDGEHUB_ADDRESS "requestL2TransactionDirect((uint256,uint256,address,uint256,bytes,uint256,uint256,bytes[],address))" "($CHAIN_ID,$VALUE_TO_BRIDGE,$ADDRESS,50,0x,300000,800,[],$ADDRESS)" --value $VALUE_TO_BRIDGE --private-key=$PRIVATE_KEY

Bridging with zksync-js

You can find examples for bridging with ethers or viem in the zksync-js docs.

Starting a local node

To start a local node, you will need to have anvil installed on your machine.

You can install anvil via foundryup by following the installation instructions in the foundry docs.

If you've used ZKsync in the past, you may remember having to use special tooling to run a local node. Since the Atlas upgrade, however, you can now use any standard EVM local node for testing. The only time you may need a ZKsync-specific node is to test bridging or crosschain transactions. For this tutorial, we won't need one.

Once installed, open a new terminal and run the command below to start a local node:

anvil

You should see some information logged about the local network running on your machine, including the port where the node is running (8545), the chain ID (31337), and 10 different test wallet addresses and their private keys. These wallets are all pre-funded with ETH so you don't need to worry about adding funds.

Keep the node running until you are done with this tutorial.

Note that this is an in-memory node, meaning that if you stop it at any time, any contracts you deployed or transactions you sent will be lost.


Made with ❤️ by the ZKsync Community