Python API

ETHSigner

Overview of account functionalities in the ZKsync Python SDK.

The ZKsync Python SDK has a method that generates a signature and a method that verifies messages.

For constructing the instance it needs only account and chain_id.

Key features

  • Wallet Management: Create and manage wallets using private keys.
  • Transaction Signing: Sign transactions using EIP712-typed data, ensuring secure and verifiable transactions.
  • Signature Verification: Verify signed transactions to ensure authenticity and integrity.

Core components

  1. sign_typed_data
    • Method to sign EIP712-typed ZKsync transactions, ensuring standardized and secure transaction formatting.
  2. verify_typed_data
    • Method to verify the signed EIP712-typed ZKsync transactions, ensuring that the transactions are authentic and have not been tampered with.

Example

from zksync2.signer.eth_signer import PrivateKeyEthSigner
from eth_account import Account
from zksync2.module.module_builder import ZkSyncBuilder


account = Account.from_key("PRIVATE_KEY")
zksync_web3 = ZkSyncBuilder.build("ZKSYNC_NETWORK_URL")

chain_id = zksync_web3.zksync.chain_id
signer = PrivateKeyEthSigner(account, chain_id)

sign_typed_data

The signer is used to generate the signature of the provided transaction based on your account(your private key).

Parameters

ParametersReturn valueDescription
EIP712 Structure, optional domainWeb3 py SignedMessageBuilds SignedMessage based on the encoded in EIP712 format Transaction.

verify_typed_data

It's used to verify the provided transaction, whose signature is added to the final EIP712 transaction for its validation.

Parameters

ParametersReturn valueDescription
signature, EIP712 structure, optional domainboolReturns True if the encoded transaction is signed with provided signature.

The signer class also has the following properties:

AttributeDescription
addressAccount address
domainDomain that is used to generate signature. It depends on chain_id of network.

get_default_domain

Represents the domain parameters used for EIP-712 signing.

Inputs

ParameterTypeDescription
chain_idintThe chain id used for generating domain.

Example

from zksync2.signer.eth_signer import PrivateKeyEthSigner
from zksync2.module.module_builder import ZkSyncBuilder

zksync_web3 = ZkSyncBuilder.build("ZKSYNC_NETWORK_URL")

chain_id = zksync_web3.zksync.chain_id
domain = PrivateKeyEthSigner.get_default_domain(chain_id)

Made with ❤️ by the ZKsync Community