Migration from v0 to v1
The v1 is designed to be simpler and more intuitive for working with the SDK.
Most changes involve removing deprecated elements and enhancing extensibility
without introducing breaking changes by eliminating unnecessary interfaces.
Here are the key design changes to keep in mind when working with v1:
- The Clientinterface has been removed.BaseClientis now renamed toClient.
- The Signerinterface has been updated to provide APIs for signing various types of payloads.
- BaseSignerhas been replaced by- ECDSASigner.
- The AdapterL1,AdapterL2, andAdapterinterfaces have been removed.
- The Transaction712has been replaced byTransaction.
Simplified Wallet Initialization
When passing the Client to WalletL1, WalletL2, or Wallet, you no longer need to pass a pointer
to the initialization function.
v0
PrivateKey        := os.Getenv("PRIVATE_KEY")
ZkSyncEraProvider := "https://testnet.era.zksync.dev"
EthereumProvider  := "https://rpc.ankr.com/eth_sepolia"
client, _    := clients.Dial(ZkSyncEraProvider)
ethClient, _ := ethclient.Dial(EthereumProvider)
wallet, _    := accounts.NewWallet(common.Hex2Bytes(PrivateKey), &client, ethClient) // <-- pass &client
v1
PrivateKey        := os.Getenv("PRIVATE_KEY")
ZkSyncEraProvider := "https://testnet.era.zksync.dev"
EthereumProvider  := "https://rpc.ankr.com/eth_sepolia"
client, _    := clients.Dial(ZkSyncEraProvider)
ethClient, _ := ethclient.Dial(EthereumProvider)
wallet, _    := accounts.NewWallet(common.Hex2Bytes(PrivateKey), client, ethClient) // <-- pass client
Balance Method
The Balance method signature has been simplified and standardized across all implementations
in WalletL1, WalletL2, Wallet, and SmartAccount.
v0
walletL1, _ := accounts.NewWalletL1(PrivateKey, &client, ethClient)
walletL2, _ := accounts.NewWalletL2(PrivateKey, &client)
wallet, _   := accounts.NewWallet(PrivateKey, &client, ethClient)
account     := accounts.NewECDSASmartAccount(Address1, PrivateKey, client)
balance1, _ := walletL1.BalanceL1(nil, utils.EthAddress)
balance2, _ := walletL2.Balance(context.Background(), utils.EthAddress, nil)
balance3, _ := wallet.Balance(context.Background(), utils.EthAddress, nil)
balance4 _ := account.Balance(context.Background(), utils.EthAddress, nil)
v1
walletL1, _ := accounts.NewWalletL1(PrivateKey, client, ethClient)
walletL2, _ := accounts.NewWalletL2(PrivateKey, client)
wallet, _   := accounts.NewWallet(PrivateKey, client, ethClient)
account     := accounts.NewECDSASmartAccount(Address1, PrivateKey, client)
balance1, _ := walletL1.BalanceL1(nil, utils.EthAddress)
balance2, _ := walletL2.Balance(nil, utils.EthAddress)
balance3, _ := wallet.Balance(nil, utils.EthAddress)
balance4, _ := account.Balance(nil, utils.EthAddress)
Transfer Optimized
The Transfer function in WalletL2 and SmartAccount has been optimized to use
EIP-712 transactions instead of legacy or EIP-1559 transactions.
This implementation reduces gas usage and enables additional ZKSync features.
v0
wallet, _ := accounts.NewWallet(PrivateKey, &client, ethClient)
tx, err := wallet.Transfer(nil, accounts.TransferTransaction{
  To:     Address2,
  Amount: amount,
  Token:  utils.L2BaseTokenAddress,
})
v1
wallet, _ := accounts.NewWallet(PrivateKey, &client, ethClient)
hash, err := wallet.Transfer(nil, accounts.TransferTransaction{
  To:     Address,
  Amount: amount,
  Token:  utils.L2BaseTokenAddress,
})
// transfer with paymaster
paymasterParams, err := utils.GetPaymasterParams(
  Paymaster,
  &types.ApprovalBasedPaymasterInput{
    Token:            ApprovalToken,
    MinimalAllowance: minimalAllowance,
    InnerInput:       []byte{},
  })
hash, err := wallet.Transfer(
  &accounts.TransactOpts{PaymasterParams: paymasterParams},
  accounts.TransferTransaction{
    To:     Address,
    Amount: amount,
    Token:  utils.EthAddress,
  })
Withdraw Optimized
The Withdraw function in WalletL2 and SmartAccount has been optimized to use
EIP-712 transactions instead of legacy or EIP-1559 transactions.
This implementation reduces gas usage and enables additional ZKSync features.
v0
wallet, _ := accounts.NewWallet(PrivateKey, &client, ethClient)
tx, err := wallet.Withdraw(nil, accounts.WithdrawalTransaction{
  To:     Address,
  Amount: amount,
  Token:  utils.L2BaseTokenAddress,
})
v1
wallet, _ := accounts.NewWallet(PrivateKey, &client, ethClient)
hash, err := wallet.Withdraw(nil, accounts.WithdrawalTransaction{
  To:     Address,
  Amount: amount,
  Token:  utils.L2BaseTokenAddress,
})
// transfer with paymaster
paymasterParams, err := utils.GetPaymasterParams(
  Paymaster,
  &types.ApprovalBasedPaymasterInput{
    Token:            ApprovalToken,
    MinimalAllowance: minimalAllowance,
    InnerInput:       []byte{},
  })
hash, err := wallet.Withdraw(
  &accounts.TransactOpts{PaymasterParams: paymasterParams},
  accounts.TransferTransaction{
    To:     Address,
    Amount: amount,
    Token:  utils.EthAddress,
  })
Renaming of Deposit Parameters
The following parameters in Wallet.Deposit have been renamed:
- ApproveERC20is now- ApproveToken.
- ApproveBaseERC20is now- ApproveBaseToken.
v0
wallet, _ := accounts.NewWallet(PrivateKey, &client, ethClient)
tx, _ := wallet.Deposit(nil, accounts.DepositTransaction{
  To:               wallet.Address(),
  Token:            L1Dai,
  Amount:           big.NewInt(5),
  ApproveERC20:     true,
  ApproveBaseERC20: true,
  RefundRecipient:  wallet.Address(),
})
v1
wallet, _ := accounts.NewWallet(PrivateKey, client, ethClient)
tx, _ := wallet.Deposit(nil, accounts.DepositTransaction{
  To:               wallet.Address(),
  Token:            L1Dai,
  Amount:           big.NewInt(5),
  ApproveToken:     true,
  ApproveBaseToken: true,
  RefundRecipient:  wallet.Address(),
})
Renaming of ApproveERC20 to ApproveToken
The method WalletL1.ApproveERC20 has been renamed to WalletL1.ApproveToken.
v0
wallet, _ := accounts.NewWallet(PrivateKey, &client, ethClient)
approveTx, _ := wallet.ApproveERC20(nil, L1Dai, big.NewInt(5), L1SharedBridge)
v1
wallet, _ := accounts.NewWallet(PrivateKey, client, ethClient)
approveTx, _ := wallet.ApproveToken(nil, L1Dai, big.NewInt(5), L1SharedBridge)