Types
This section describes various types used in the ZKsync Era. These types are essential for interacting with the blockchain, performing transactions, and managing accounts.
AllowanceParams
Contains the parameters required for approval of an ERC20 token.
type AllowanceParams struct {
Token common.Address // Token address
Allowance *big.Int // Allowance amount
}
Cache
Holds cached bridge addresses and contracts for optimized access. This cache uses a lazy-loading approach, meaning data is only fetched when needed.
type Cache struct {}
// NewCache creates an instance of Cache with the provided clients.
// Contracts returned from Cache are associated with the provided clients.
func NewCache(clientL2 *clients.Client, clientL1 *ethclient.Client) *Cache
// MainContractAddress returns the main contract address from cache.
// If not already cached, it fetches the addresses,
// caches it, and then returns the value from the cache.
func (c *Cache) MainContractAddress() (common.Address, error)
// BridgehubAddress returns the Bridgehub contract address from cache.
// If not already cached, it fetches the addresses,
// caches it, and then returns the value from the cache.
func (c *Cache) BridgehubAddress() (common.Address, error)
// L2DefaultBridgeAddress returns the L2 default bridge address from cache.
// If not already cached, it fetches the bridge addresses,
// caches them, and then returns the value from the cache.
func (c *Cache) L2DefaultBridgeAddress() (common.Address, error)
// L1DefaultBridgeAddress returns the L1 default bridge address from cache.
// If not already cached, it fetches the bridge addresses,
// caches them, and then returns the value from the cache.
func (c *Cache) L1DefaultBridgeAddress() (common.Address, error)
// L2SharedBridgeAddress returns the L2 shared bridge address from cache.
// If not already cached, it fetches the bridge addresses,
// caches them, and then returns the value from the cache.
func (c *Cache) L2SharedBridgeAddress() (common.Address, error)
// L1SharedBridgeAddress returns the L1 shared bridge address from cache.
// If not already cached, it fetches the bridge addresses,
// caches them, and then returns the value from the cache.
func (c *Cache) L1SharedBridgeAddress() (common.Address, error)
// MainContract returns the main contract from cache.
// It is not cached, fetches the contract, cache it and
// returns the value from cache.
func (c *Cache) MainContract() (*hyperchain.IZkSyncHyperchain, error)
// Bridgehub returns the Bridgehub contract from cache.
// It is not cached, fetches the contract, cache it and
// returns the value from cache.
func (c *Cache) Bridgehub() (*bridgehub.IBridgehub, error)
// L2BridgeContracts returns the L2 bridge contracts from cache.
// It is not cached, fetches the contracts, cache them and
// returns the value from cache.
func (c *Cache) L2BridgeContracts() (*types.L2BridgeContracts, error)
// L1BridgeContracts returns the L1 bridge contracts from cache.
// It is not cached, fetches the contracts, cache them and
// returns the value from cache.
func (c *Cache) L1BridgeContracts() (*types.L1BridgeContracts, error)
// L2DefaultBridge returns the L2 default bridge contract from cache.
// It is not cached, fetches the contract, cache it and
// returns the value from cache.
func (c *Cache) L2DefaultBridge() (*l2bridge.IL2Bridge, error)
// L1DefaultBridge returns the L1 default bridge contract from cache.
// It is not cached, fetches the contract, cache it and
// returns the value from cache.
func (c *Cache) L1DefaultBridge() (*l1bridge.IL1Bridge, error)
// L2SharedBridge returns the L2 shared bridge contract from cache.
// It is not cached, fetches the contract, cache it and
// returns the value from cache.
func (c *Cache) L2SharedBridge() (*l2sharedbridge.IL2SharedBridge, error)
// L1SharedBridge returns the L2 shared bridge contract from cache.
// It is not cached, fetches the contract, cache it and
// returns the value from cache.
func (c *Cache) L1SharedBridge() (*l1sharedbridge.IL1SharedBridge, error)
CallMsg
Contains parameters for contract call from a specific account associated
with WalletL1
, WalletL2
or Deployer
.
Its primary purpose is to be transformed into types.CallMsg
, wherein the From
field represents the associated account.
type CallMsg struct {
To *common.Address // The address of the recipient.
Gas uint64 // If 0, the call executes with near-infinite gas.
GasPrice *big.Int // Wei <-> gas exchange ratio.
GasFeeCap *big.Int // EIP-1559 fee cap per gas.
GasTipCap *big.Int // EIP-1559 tip per gas.
Value *big.Int // Amount of wei sent along with the call.
Data []byte // Input data, usually an ABI-encoded contract method invocation
// GasPerPubdata denotes the maximum amount of gas the user is willing
// to pay for a single byte of pubdata.
GasPerPubdata *big.Int
// CustomSignature is used for the cases in which the signer's account
// is not an EOA.
CustomSignature hexutil.Bytes
// FactoryDeps is a non-empty array of bytes. For deployment transactions,
// it should contain the bytecode of the contract being deployed.
// If the contract is a factory contract, i.e. it can deploy other contracts,
// the array should also contain the bytecodes of the contracts which it can deploy.
FactoryDeps []hexutil.Bytes
// PaymasterParams contains parameters for configuring the custom paymaster
// for the transaction.
PaymasterParams *types.PaymasterParams
}
// ToCallMsg transforms CallMsg to types.CallMsg.
func (m *CallMsg) ToCallMsg(from common.Address) types.CallMsg
CallOpts
Ss the collection of options to fine tune a contract call request from
a specific associated account.
Its primary purpose is to be transformed into bind.CallOpts
, wherein the From
field represents the associated account.
type CallOpts struct {
Pending bool // Whether to operate on the pending state or the last known one
BlockNumber *big.Int // Optional the block number on which the call should be performed
Context context.Context // Network context to support cancellation and timeouts (nil = no timeout)
}
// ToCallOpts transforms CallOpts to bind.CallOpts.
func (o *CallOpts) ToCallOpts(from common.Address) *bind.CallOpts
Create2Transaction
Represents the parameters for deploying a contract or account using the CREATE2 opcode.
This transaction is initiated by the account associated with Deployer
.
type Create2Transaction struct {
Bytecode []byte // The bytecode of smart contract or smart account.
Calldata []byte // The constructor calldata.
Salt []byte // The create2 salt.
Dependencies [][]byte // The bytecode of dependent smart contracts or smart accounts.
Auth *TransactOpts // Authorization data.
}
// ToTransaction transforms Create2Transaction to Transaction.
func (t *Create2Transaction) ToTransaction(deploymentType DeploymentType) (*Transaction, error)
CreateTransaction
Represents the parameters for deploying a contract or account using the CREATE opcode.
This transaction is initiated by the account associated with Deployer
.
type CreateTransaction struct {
Bytecode []byte // The bytecode of smart contract or smart account.
Calldata []byte // The constructor calldata.
Dependencies [][]byte // The bytecode of dependent smart contracts or smart accounts.
Auth *TransactOpts // Authorization data.
}
// ToTransaction transforms CreateTransaction to Transaction.
func (t *CreateTransaction) ToTransaction(deploymentType DeploymentType) (*Transaction, error)
DeploymentType
Represents an enumeration of deployment types.
type DeploymentType string
const (
DeployContract DeploymentType = "CONTRACT"
DeployAccount DeploymentType = "ACCOUNT"
)
DepositCallMsg
contains the common data required to execute a deposit call on L2 from L1.
This execution is initiated by the account associated with WalletL1
.
type DepositCallMsg struct {
To common.Address // The address that will receive the deposited tokens on L2.
Token common.Address // The address of the token to deposit.
Amount *big.Int // The amount of the token to be deposited.
// If the ETH value passed with the transaction is not explicitly stated Value,
// this field will be equal to the tip the operator will receive on top of the base cost
// of the transaction.
OperatorTip *big.Int
BridgeAddress *common.Address // The address of the bridge contract to be used.
L2GasLimit *big.Int // Maximum amount of L2 gas that transaction can consume during execution on L2.
// The maximum amount L2 gas that the operator may charge the user for single byte of pubdata.
GasPerPubdataByte *big.Int
// The address on L2 that will receive the refund for the transaction.
// If the transaction fails, it will also be the address to receive L2Value.
RefundRecipient common.Address
CustomBridgeData []byte // Additional data that can be sent to a bridge.
Value *big.Int // The amount of wei sent along with the call.
Gas uint64 // If 0, the call executes with near-infinite gas.
GasPrice *big.Int // Wei <-> gas exchange ratio.
GasFeeCap *big.Int // EIP-1559 fee cap per gas.
GasTipCap *big.Int // EIP-1559 tip per gas.
}
// ToDepositTransaction transforms DepositCallMsg to DepositTransaction.
func (m *DepositCallMsg) ToDepositTransaction() DepositTransaction
// ToRequestExecuteCallMsg transforms DepositCallMsg to RequestExecuteCallMsg.
func (m *DepositCallMsg) ToRequestExecuteCallMsg() RequestExecuteCallMsg
// ToCallMsg transforms DepositCallMsg to ethereum.CallMsg.
func (m *DepositCallMsg) ToCallMsg(from, l1Bridge common.Address) (ethereum.CallMsg, error)
// ToTransactOpts transforms DepositCallMsg to TransactOptsL1.
func (m *DepositCallMsg) ToTransactOpts() TransactOptsL1
// PopulateEmptyFields populates required empty fields with default values.
func (m *DepositCallMsg) PopulateEmptyFields(from common.Address)
DepositTransaction
Represents a deposit transaction on L2 from L1 initiated by the account associated with WalletL1
.
type DepositTransaction struct {
To common.Address // The address of the token to deposit.
Token common.Address // The address of the token to deposit.
Amount *big.Int // The amount of the token to be deposited.
// If the ETH value passed with the transaction is not explicitly stated Auth.Value,
// this field will be equal to the tip the operator will receive on top of the base cost
// of the transaction.
OperatorTip *big.Int
BridgeAddress *common.Address // The address of the bridge contract to be used.
// Whether should the token approval be performed under the hood. Set this flag to true if you
// bridge an ERC20 token and didn't call the ApproveToken function beforehand.
ApproveToken bool
// Whether should the base token approval be performed under the hood. Set this flag to true if you
// bridge an ERC20 token and didn't call the ApproveToken function beforehand.
ApproveBaseToken bool
L2GasLimit *big.Int // Maximum amount of L2 gas that transaction can consume during execution on L2.
// The maximum amount L2 gas that the operator may charge the user for single byte of pubdata.
GasPerPubdataByte *big.Int
// The address on L2 that will receive the refund for the transaction.
// If the transaction fails, it will also be the address to receive L2Value.
RefundRecipient common.Address
CustomBridgeData []byte // Additional data that can be sent to the bridge.
ApproveAuth *TransactOptsL1 // Authorization data for the token approval transaction.
ApproveBaseAuth *TransactOptsL1 // Authorization data for the base token approval transaction.
}
// ToRequestExecuteTransaction transforms DepositTransaction to RequestExecuteTransaction.
func (t *DepositTransaction) ToRequestExecuteTransaction() *RequestExecuteTransaction
// ToDepositCallMsg transforms DepositTransaction to DepositCallMsg.
func (t *DepositTransaction) ToDepositCallMsg(opts *TransactOptsL1) DepositCallMsg
// PopulateEmptyFields populates required empty fields with default values.
func (t *DepositTransaction) PopulateEmptyFields(from common.Address)
FullDepositFee
Represents the total ETH fee required for performing the deposit on both L1 and L2 networks.
type FullDepositFee struct {
MaxFeePerGas, // MaxFeePerGas of the L1 transaction if 1559 transaction is used.
MaxPriorityFeePerGas, // MaxPriorityFeePerGas of the L1 transaction if 1559 transaction is used.
GasPrice, // Gas price of the L1 transaction if legacy transaction is used.
BaseCost, // Base cost of the L2 transaction.
L1GasLimit, // Gas limit of the L1 transaction.
L2GasLimit *big.Int // Gas limit of the L2 transaction.
}
PayloadSigner
Signs various types of payloads, optionally using a some kind of secret. Returns the serialized signature. The client is used to fetch data from the network if it is required for signing.
type PayloadSigner func(ctx context.Context, payload []byte, secret interface{}, client *clients.Client) ([]byte, error)
RequestExecuteCallMsg
Contains the common data required to execute a call for a request execution of an L2
transaction from L1. This execution is initiated by the account associated with WalletL1
.
type RequestExecuteCallMsg struct {
ContractAddress common.Address // The L2 receiver address.
Calldata []byte // The input of the L2 transaction.
L2GasLimit *big.Int // Maximum amount of L2 gas that transaction can consume during execution on L2.
MintValue *big.Int // The amount of base token that needs to be minted on non-ETH-based L2.
L2Value *big.Int // `msg.value` of L2 transaction.
FactoryDeps [][]byte // An array of L2 bytecodes that will be marked as known on L2.
// If the ETH value passed with the transaction is not explicitly stated Value,
// this field will be equal to the tip the operator will receive on top of the base cost
// of the transaction.
OperatorTip *big.Int
// The maximum amount L2 gas that the operator may charge the user for single byte of pubdata.
GasPerPubdataByte *big.Int
// The address on L2 that will receive the refund for the transaction.
// If the transaction fails, it will also be the address to receive L2Value.
RefundRecipient common.Address
Value *big.Int // The amount of wei sent along with the call.
Gas uint64 // If 0, the call executes with near-infinite gas.
GasPrice *big.Int // Wei <-> gas exchange ratio.
GasFeeCap *big.Int // EIP-1559 fee cap per gas.
GasTipCap *big.Int // EIP-1559 tip per gas.
}
// ToRequestExecuteTransaction transforms RequestExecuteCallMsg to RequestExecuteTransaction.
func (m *RequestExecuteCallMsg) ToRequestExecuteTransaction() RequestExecuteTransaction
// ToCallMsgWithChainID transforms RequestExecuteCallMsg to ethereum.CallMsg.
func (m *RequestExecuteCallMsg) ToCallMsgWithChainID(from common.Address, chainID *big.Int) (ethereum.CallMsg, error)
// ToTransactOpts transforms RequestExecuteCallMsg to TransactOptsL1.
func (m *RequestExecuteCallMsg) ToTransactOpts() TransactOptsL1
RequestExecuteTransaction
Represents a request execution of L2 transaction from L1 initiated by the account associated with WalletL1
.
type RequestExecuteTransaction struct {
ContractAddress common.Address // The L2 receiver address.
Calldata []byte // The input of the L2 transaction.
L2GasLimit *big.Int // Maximum amount of L2 gas that transaction can consume during execution on L2.
MintValue *big.Int // The amount of base token that needs to be minted on non-ETH-based L2.
L2Value *big.Int // `msg.value` of L2 transaction.
FactoryDeps [][]byte // An array of L2 bytecodes that will be marked as known on L2.
// If the ETH value passed with the transaction is not explicitly stated Auth.Value,
// this field will be equal to the tip the operator will receive on top of the base cost
// of the transaction.
OperatorTip *big.Int
// The maximum amount L2 gas that the operator may charge the user for single byte of pubdata.
GasPerPubdataByte *big.Int
// The address on L2 that will receive the refund for the transaction.
// If the transaction fails, it will also be the address to receive L2Value.
RefundRecipient common.Address
}
// ToRequestExecuteCallMsg transforms RequestExecuteTransaction to RequestExecuteCallMsg.
func (t *RequestExecuteTransaction) ToRequestExecuteCallMsg(opts *TransactOptsL1) RequestExecuteCallMsg
// ToCallMsg transforms RequestExecuteTransaction to types.CallMsg.
func (t *RequestExecuteTransaction) ToCallMsg(from common.Address, opts *TransactOptsL1) types.CallMsg
Transaction
Similar to types.Transaction
but does not include the From
field. This design is intended for use
with entities which already have an associated account. The From
field is bound to
their associated account, and thus, it is not included in this type.
type Transaction struct {
To *common.Address // The address of the recipient.
Data hexutil.Bytes // Input data, usually an ABI-encoded contract method invocation.
Value *big.Int // Funds to transfer along the transaction (nil = 0 = no funds).
Nonce *big.Int // Nonce to use for the transaction execution.
GasTipCap *big.Int // EIP-1559 tip per gas.
GasFeeCap *big.Int // EIP-1559 fee cap per gas.
Gas uint64 // Gas limit to set for the transaction execution.
ChainID *big.Int // Chain ID of the network.
// GasPerPubdata denotes the maximum amount of gas the user is willing
// to pay for a single byte of pubdata.
GasPerPubdata *big.Int `json:"gasPerPubdata,omitempty"`
// CustomSignature is used for the cases in which the signer's account
// is not an EOA.
CustomSignature hexutil.Bytes `json:"customSignature,omitempty"`
// FactoryDeps is a non-empty array of bytes. For deployment transactions,
// it should contain the bytecode of the contract being deployed.
// If the contract is a factory contract, i.e. it can deploy other contracts,
// the array should also contain the bytecodes of the contracts which it can deploy.
FactoryDeps []hexutil.Bytes `json:"factoryDeps"`
// PaymasterParams contains parameters for configuring the custom paymaster
// for the transaction.
PaymasterParams *types.PaymasterParams `json:"paymasterParams,omitempty"`
}
// ToTransaction transforms Transaction to types.Transaction.
func (t *Transaction) ToTransaction(from common.Address) *types.Transaction
// ToCallMsg transforms Transaction to types.CallMsg.
func (t *Transaction) ToCallMsg(from common.Address) types.CallMsg
TransactionBuilder
Populates missing fields in a tx with default values. The client is used to fetch data from the network if it is required.
type TransactionBuilder func(ctx context.Context, tx *zkTypes.Transaction, secret interface{}, client *clients.Client) error
TransactOpts
Contains common data required to create a valid transaction on L2 using the account
associated with WalletL2
and Deployer
. Its primary purpose is to be transformed into
bind.TransactOpts
,
wherein the From
and Signer
fields are linked to the associated account.
type TransactOpts struct {
Nonce *big.Int // Nonce to use for the transaction execution (nil = use pending state).
Value *big.Int // Funds to transfer along the transaction (nil = 0 = no funds).
GasPrice *big.Int // Gas price to use for the transaction execution (nil = gas price oracle).
GasFeeCap *big.Int // Gas fee cap to use for the 1559 transaction execution (nil = gas price oracle).
GasTipCap *big.Int // Gas priority fee cap to use for the 1559 transaction execution (nil = gas price oracle).
GasLimit uint64 // Gas limit to set for the transaction execution (0 = estimate).
Context context.Context // Network context to support cancellation and timeouts (nil = no timeout).
PaymasterParams *types.PaymasterParams // The paymaster parameters.
// GasPerPubdata denotes the maximum amount of gas the user is willing
// to pay for a single byte of pubdata.
GasPerPubdata *big.Int
}
TransactOptsL1
Contains common data required to create a valid transaction on L1 using the account
associated with WalletL1
. Its primary purpose is to be transformed into
bind.TransactOpts
,
wherein the From
and Signer
fields are linked to the associated account.
type TransactOptsL1 struct {
Nonce *big.Int // Nonce to use for the transaction execution (nil = use pending state).
Value *big.Int // Funds to transfer along the transaction (nil = 0 = no funds).
GasPrice *big.Int // Gas price to use for the transaction execution (nil = gas price oracle).
GasFeeCap *big.Int // Gas fee cap to use for the 1559 transaction execution (nil = gas price oracle).
GasTipCap *big.Int // Gas priority fee cap to use for the 1559 transaction execution (nil = gas price oracle).
GasLimit uint64 // Gas limit to set for the transaction execution (0 = estimate).
Context context.Context // Network context to support cancellation and timeouts (nil = no timeout).
}
// ToTransactOpts transforms TransactOptsL1 to bind.TransactOpts.
func (t *TransactOptsL1) ToTransactOpts(from common.Address, signer bind.SignerFn) *bind.TransactOpts
TransferCallMsg
Contains the common data required to execute a transfer call on L2.
This execution is initiated by the account associated with WalletL2
.
type TransferCallMsg struct {
To common.Address // The address of the recipient.
Amount *big.Int // The amount of the token to transfer.
Token common.Address // The address of the token. ETH by default.
Gas uint64 // If 0, the call executes with near-infinite gas.
GasPrice *big.Int // Wei <-> gas exchange ratio.
GasFeeCap *big.Int // EIP-1559 fee cap per gas.
GasTipCap *big.Int // EIP-1559 tip per gas.
PaymasterParams *types.PaymasterParams // The paymaster parameters.
// GasPerPubdata denotes the maximum amount of gas the user is willing
// to pay for a single byte of pubdata.
GasPerPubdata *big.Int
}
// ToTransferCallMsg transforms TransferCallMsg to clients.TransferCallMsg.
func (m *TransferCallMsg) ToTransferCallMsg(from common.Address) clients.TransferCallMsg
TransferTransaction
Represents a transfer transaction on L2 initiated by the account associated with AdapterL2
.
type TransferTransaction struct {
To common.Address // The address of the recipient.
Amount *big.Int // The amount of the token to transfer.
Token common.Address // The address of the token. ETH by default.
}
// ToTransaction transforms TransferTransaction to Transaction.
func (t *TransferTransaction) ToTransaction(opts *TransactOpts) *Transaction
// ToTransferCallMsg transforms TransferTransaction to clients.TransferCallMsg.
func (t *TransferTransaction) ToTransferCallMsg(from common.Address, opts *TransactOpts) clients.TransferCallMsg
WithdrawalCallMsg
Contains the common data required to execute a withdrawal call on L1 from L2.
This execution is initiated by the account associated with WalletL2
.
type WithdrawalCallMsg struct {
To common.Address // The address of the recipient on L1.
Amount *big.Int // The amount of the token to transfer.
Token common.Address // The address of the token. ETH by default.
BridgeAddress *common.Address // The address of the bridge contract to be used.
Gas uint64 // If 0, the call executes with near-infinite gas.
GasPrice *big.Int // Wei <-> gas exchange ratio.
GasFeeCap *big.Int // EIP-1559 fee cap per gas.
GasTipCap *big.Int // EIP-1559 tip per gas.
PaymasterParams *types.PaymasterParams // The paymaster parameters.
// GasPerPubdata denotes the maximum amount of gas the user is willing
// to pay for a single byte of pubdata.
GasPerPubdata *big.Int
}
// ToWithdrawalCallMsg transforms WithdrawalCallMsg to clients.WithdrawalCallMsg.
func (m *WithdrawalCallMsg) ToWithdrawalCallMsg(from common.Address) clients.WithdrawalCallMsg
WithdrawalTransaction
Represents a withdrawal transaction on L1 from L2 initiated by the account associated with WalletL2
.
type WithdrawalTransaction struct {
To common.Address // The address that will receive the withdrawn tokens on L1.
Token common.Address // The address of the token to withdraw.
Amount *big.Int // The amount of the token to withdraw.
BridgeAddress *common.Address // The address of the bridge contract to be used.
}
// ToWithdrawalCallMsg transforms WithdrawalTransaction to clients.WithdrawalCallMsg.
func (t *WithdrawalTransaction) ToWithdrawalCallMsg(from common.Address, opts *TransactOpts) *clients.WithdrawalCallMsg