Skip to content
This repository has been archived by the owner on Oct 3, 2024. It is now read-only.

Commit

Permalink
feat(java-sdk): add missing docs (#979)
Browse files Browse the repository at this point in the history
  • Loading branch information
petarTxFusion authored Mar 25, 2024
1 parent 31801af commit 7942df6
Show file tree
Hide file tree
Showing 9 changed files with 1,466 additions and 1,435 deletions.
92 changes: 15 additions & 77 deletions docs/build/sdks/java/accounts-l1-l2.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,92 +5,30 @@ head:
content: Java SDK L1/L2 Transactions | zkSync Docs
---

# Accounts: L1->L2 Transactions
# Accounts: L1<->L2 Transactions

This section explores the methods which allow the [account](./accounts.md) classes to send transactions from L1 to L2.
This section explores the methods which allow the [account](./accounts.md) to send transactions among both L1 to L2 networks.

If you want some background on how L1->L2 interaction works on zkSync Era, go through the [L1 / L2 interoperability doc](../../developer-reference/l1-l2-interop.md).
If you want some background on how L1<->L2 interaction works on zkSync, go through the [introduction](../../developer-reference/l1-l2-interop.md).

## EthereumProvider
## Deposit

### `approveDeposits`
`Wallet` and `L1Signer` objects provide a deposit workflow. For more information, please refer to the method specification [`Deposit`](accounts.md#deposit).

Send approve transaction to token contract.
For a complete example of how to execute the deposit workflow, take a look at the following: [Deposit ETH and ERC20 token](https://github.com/zksync-sdk/zksync2-examples/blob/main/js/src/01_deposit.ts).

Example:
## Request execute

```java
TransactionReceipt approveReceipt = provider.approveDeposits(token, Optional.of(token.toBigInteger(10000000000L))).join();
```
`Wallet` and `L1Signer` objects provide an option to request execution of L2 transaction from L1. For more information, please refer
to the method specification [`requestExecute`](accounts.md#requestexecute).

| Name | Description |
| ------ | ----------------------------------------------------- |
| token | Token object supported by ZkSync Era. |
| limit | Maximum amount to approve for ZkSync Era contract. |
| return | `CompletableFuture` for waiting for transaction mine. |
## Base cost

### `deposit`
`Wallet` and `L1Signer` objects provide an option to calculate base cost for L2 transaction. For more information, please refer to the
method specification [`getBaseCost`](accounts.md#getbasecost).

Send deposit transaction to ZkSync Era contract. For ERC20 token must be approved before. See [approveDeposits](#approvedeposits)
## Withdrawal

| Name | Description |
| ------------ | ----------------------------------------------------- |
| token | Token object supported by ZkSync Era. |
| amount | Amount of tokens to transfer. |
| operatorTips | Tips for operator that executes deposit on L2. |
| userAddress | Address of L2 receiver of deposit in ZkSync Era. |
| return | `CompletableFuture` for waiting for transaction mine. |
`Wallet` and `Signer` objects provide a withdrawal workflow. For more information, please refer to the method specification [`Deposit`](accounts.md#deposit).

Example:

```java
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:

```java
BigInteger baseCost = provider.getBaseCost(gasLimit, L1_TO_L2_GAS_PER_PUBDATA, gasPriceValue).join();
```

| Name | Description |
| ----------------- | ----------------------------------------------------- |
| gasLimit | Gas limit for L2 transaction. |
| gasPerPubdataByte | Gas per pubdata byte. |
| gasPrice | Gas price for L2 transaction. |
| return | `CompletableFuture` for waiting for transaction mine. |

### `transfer`

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

Example:

```java
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);
```

| Name | Description |
| ------ | ----------------------------------------------------- |
| token | Token object supported by ZkSync Era. |
| amount | Amount of tokens to transfer. |
| to | Address of token recipient. |
| return | `CompletableFuture` for waiting for transaction mine. |
For a complete example of how to execute the deposit workflow, take a look at the following: [Withdraw ETH and ERC20 token](https://github.com/zksync-sdk/zksync2-examples/blob/main/js/src/03_withdraw.ts).
Loading

0 comments on commit 7942df6

Please sign in to comment.