Accounts: L1->L2 transactions


Accounts: L1->L2 transactions

This section explores the methods which allow the account classes to send transactions from L1 to L2.

If you want some background on how L1->L2 interaction works on zkSync Era, go through the L1 / L2 interoperability doc.

EthereumProvider

approveDeposits

Send approve transaction to token contract.

Example:

TransactionReceipt approveReceipt = provider.approveDeposits(token, Optional.of(token.toBigInteger(10000000000L))).join();
NameDescription
tokenToken object supported by ZkSync Era.
limitMaximum amount to approve for ZkSync Era contract.
returnCompletableFuture for waiting for transaction mine.

deposit

Send deposit transaction to ZkSync Era contract. For ERC20 token must be approved before. See approveDeposits

NameDescription
tokenToken object supported by ZkSync Era.
amountAmount of tokens to transfer.
operatorTipsTips for operator that executes deposit on L2.
userAddressAddress of L2 receiver of deposit in ZkSync Era.
returnCompletableFuture for waiting for transaction mine.

Example:

  TransactionManager manager = new RawTransactionManager(web3j, credentials, chainId.longValue());
  BigInteger gasPrice = web3j.ethGasPrice().send().getGasPrice();
  ContractGasProvider gasProvider = new StaticGasProvider(gasPrice, BigInteger.valueOf(300_000L));
  TransactionReceipt receipt = EthereumProvider
  .load(wallet.getZksync(), web3j, manager, gasProvider).join()
  .deposit(Token.ETH, Convert.toWei("0.001", Convert.Unit.ETHER).toBigInteger(), BigInteger.ZERO, credentials.getAddress()).join();

  System.out.println(receipt);

getBaseCost

Get base cost for L2 transaction.

Example:

BigInteger baseCost = provider.getBaseCost(gasLimit, L1_TO_L2_GAS_PER_PUBDATA, gasPriceValue).join();
NameDescription
gasLimitGas limit for L2 transaction.
gasPerPubdataByteGas per pubdata byte.
gasPriceGas price for L2 transaction.
returnCompletableFuture for waiting for transaction mine.

transfer

Send transfer transaction. This is the regular transfer of ERC20 tokens.

Example:

TransactionManager manager = new RawTransactionManager(web3j, credentials, chainId.longValue());
BigInteger gasPrice = web3j.ethGasPrice().send().getGasPrice();
ContractGasProvider gasProvider = new StaticGasProvider(gasPrice, BigInteger.valueOf(300_000L));
TransactionReceipt receipt = EthereumProvider
 .load(wallet.getZksync(), web3j, manager, gasProvider).join()
 .transfer(Token.ETH, Convert.toWei("0.117649", Convert.Unit.ETHER).toBigInteger(), credentials.getAddress()).join();

 System.out.println(receipt);
NameDescription
tokenToken object supported by ZkSync Era.
amountAmount of tokens to transfer.
toAddress of token recipient.
returnCompletableFuture for waiting for transaction mine.