Getting Started


Getting Started

Concept

While most of the existing SDKs should work out of the box, deploying smart contracts or using unique zkSync features, like account abstraction, requires providing additional fields to those that Ethereum transactions have by default.

To provide easy access to all the features of zkSync Era, the zksync2 Python SDK was created, which is made in a way that has an interface very similar to those of web3.pyopen in new window. In fact, web3.py is a peer dependency of our library and most of the objects exported by zksync2 inherit from the corresponding web3.py objects and override only the fields that need to be changed.

Prerequisites

Adding dependencies

To install zkSync Era, run the command below in your terminal.

pip install zksync2

Connecting to zkSync Era

Once you have all the necessary dependencies, connect to zkSync Era using the endpoint of the operator node.

from zksync2.module.module_builder import ZkSyncBuilder
...
sdk = ZkSyncBuilder.build("https://sepolia.era.zksync.dev")

Get chain id:

chain_id = zk_web3.zksync.chain_id

Get block number:

block_number = zk_web3.zksync.block_number

Get the transaction by hash:

transaction = zksync_web3.zksync.eth_get_transaction_by_hash(hash);

Also, the following examples demonstrate how to:

  1. Deposit ETH and tokens from Ethereum into zkSync Eraopen in new window
  2. Transfer ETH and tokens on zkSync Eraopen in new window
  3. Withdraw ETH and tokens from zkSync Era to Ethereumopen in new window
  4. Use paymaster to pay fee with tokenopen in new window

Full code for all examples is available hereopen in new window. Examples are configured to interact with zkSync Era and Sepolia test networks.