Overview
An introduction to the ZKsync Python SDK and its features.
Concept
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.
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)
Examples
These examples show how to:
- Deposit ETH and tokens from Ethereum into ZKsync Era
- Transfer ETH and tokens on ZKsync Era
- Withdraw ETH and tokens from ZKsync Era to Ethereum
- 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.