Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update documentation with. zksync2-examples #74

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 73 additions & 2 deletions content/sdk/10.js/00.ethers/04.guides/02.accounts-l1-l2.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,42 @@ If you need background information on how L1<->L2 interactions work on ZKsync, c
`Wallet` and `L1Signer` objects allow you to deposit funds from L1 to L2.

- **More Information**: See the method specification [`Deposit`](/sdk/js/ethers/api/v5/accounts/wallet#deposit).
- **Example**: [Deposit ETH and ERC20 token](https://github.com/zksync-sdk/zksync2-examples/blob/main/js/src/01_deposit.ts).
- **Example**: Deposit ETH and ERC20 token

::collapsible

```bash
import { Provider, types, utils, Wallet } from "zksync-ethers";
import { ethers } from "ethers";

const provider = Provider.getDefaultProvider(types.Network.Sepolia);
const ethProvider = ethers.getDefaultProvider("sepolia");
const PRIVATE_KEY = process.env.PRIVATE_KEY;
const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider);

async function main() {
console.log(`L2 balance before deposit: ${await wallet.getBalance()}`);
console.log(`L1 balance before deposit: ${await wallet.getBalanceL1()}`);

const tx = await wallet.deposit({
token: utils.ETH_ADDRESS,
to: await wallet.getAddress(),
amount: ethers.parseEther("0.00020"),
refundRecipient: await wallet.getAddress(),
});
const receipt = await tx.wait();
console.log(`Tx: ${receipt.hash}`);

console.log(`L2 balance after deposit: ${await wallet.getBalance()}`);
console.log(`L1 balance after deposit: ${await wallet.getBalanceL1()}`);
}

main()
.then()
.catch((error) => {
console.log(`Error: ${error}`);
});
::

## Request execute

Expand Down Expand Up @@ -44,4 +79,40 @@ If you need background information on how L1<->L2 interactions work on ZKsync, c
`Wallet` and `Signer` objects enable you to withdraw funds from L2 to L1.

- **More Information**: See the method specification [`Withdraw`](/sdk/js/ethers/api/v5/accounts/wallet#withdraw).
- **Example**: [Withdraw ETH and ERC20 token](https://github.com/zksync-sdk/zksync2-examples/blob/main/js/src/04_withdraw.ts).
- **Example**: Withdraw ETH and ERC20 token

::collapsible
```bash

import { Provider, types, utils, Wallet } from "zksync-ethers";
import { ethers } from "ethers";

const provider = Provider.getDefaultProvider(types.Network.Sepolia);
const ethProvider = ethers.getDefaultProvider("sepolia");
const PRIVATE_KEY = process.env.PRIVATE_KEY;
const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider);

async function main() {
console.log(`L2 balance before withdraw: ${await wallet.getBalance()}`);
console.log(`L1 balance before withdraw: ${await wallet.getBalanceL1()}`);

const tx = await wallet.withdraw({
token: utils.ETH_ADDRESS,
to: await wallet.getAddress(),
amount: ethers.parseEther("0.00020"),
});
const receipt = await tx.wait();
console.log(`Tx: ${receipt.hash}`);

// The duration for submitting a withdrawal transaction to L1 can last up to 24 hours. For additional information,
// please refer to the documentation: https://era.zksync.io/docs/reference/troubleshooting/withdrawal-delay.html.
// Once the withdrawal transaction is submitted on L1, it needs to be finalized.
// To learn more about how to achieve this, please take a look at the 04_finalize_withdraw.ts script.
}

main()
.then()
.catch((error) => {
console.log(`Error: ${error}`);
});
::
2 changes: 1 addition & 1 deletion content/sdk/20.go/00.introduction/01.why-zksync2-go.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Why zksync2-go
description: Benefits and Advantages of using `zksync2-go`
description: Benefits and Advantages of using zksync2-go
tags: ["zksync", "zksync2-go", "ethereum", "layer-2", "zero-knowledge rollups", "go library"]
---

Expand Down
Loading
Loading