An introduction to the ZKsync Python SDK and its features.


Most existing SDKs work right away, but deploying smart contracts or using unique ZKsync features, like account abstraction, needs extra fields that Ethereum transactions don't have by default.

To make it easy to use all ZKsync Era features, we created the zksync2 Python SDK. This SDK has an interface similar to web3.py. In fact, web3.py is a peer dependency of our library. Most objects exported by zksync2 inherit from web3.py objects and only change the fields that need adjustments.

Explore the Python SDK examples to quickly and efficiently develop applications with the ZKsync protocol.

Check the installation guide for instructions. ::

Connecting to ZKsync Era

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

from zksync2.module.module_builder import ZkSyncBuilder

sdk = ZkSyncBuilder.build("https://sepolia.era.zksync.dev")

Get the chain ID:

chain_id = zk_web3.zksync.chain_id

Get the block number:

block_number = zk_web3.zksync.block_number

Get the transaction by hash:

transaction = zk_web3.zksync.eth_get_transaction_by_hash(hash)


These examples show how to:

  1. Deposit ETH and tokens from Ethereum into ZKsync Era
  2. Transfer ETH and tokens on ZKsync Era
  3. Withdraw ETH and tokens from ZKsync Era to Ethereum
  4. Use paymaster to pay fees with tokens

You can find the full code for all examples in the Python ZKsync SDK. These examples are set up to work with ZKsync Era and Sepolia test networks.

Made with ❤️ by the ZKsync Community