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.py. 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
- Python: >=3.8 (installation guide)
- Pip: 23.1.2 (installation guide)
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:
- 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 fee with token
Full code for all examples is available here. Examples are configured to interact with zkSync Era
and Sepolia
test networks.