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

Commit

Permalink
feat(js-sdk): add documentation Provider.getProof (#903)
Browse files Browse the repository at this point in the history
  • Loading branch information
danijelTxFusion authored Feb 9, 2024
1 parent d9c9a32 commit 48ef1cf
Show file tree
Hide file tree
Showing 7 changed files with 660 additions and 171 deletions.
199 changes: 156 additions & 43 deletions docs/build/sdks/js/accounts.md
Original file line number Diff line number Diff line change
Expand Up @@ -593,39 +593,70 @@ For convenience, the `Wallet` class has `transfer` method, which can transfer `E

#### Inputs

| Parameter | Type | Description |
| ------------ | ---------------------- | ----------------------------------------------------------------------------------------------------- |
| `tx.to` | `Address` | The address of the recipient. |
| `tx.amount` | `BigNumberish` | The amount of the token to transfer (optional). |
| `tx.token?` | `Address` | The address of the token. `ETH` by default (optional). |
| `overrides?` | `ethers.CallOverrides` | Transaction's overrides which may be used to pass l2 `gasLimit`, `gasPrice`, `value`, etc (optional). |
| Parameter | Type | Description |
| ------------------------------ | ----------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| `transaction.to` | `Address` | The address of the recipient. |
| `transaction.amount` | `BigNumberish` | The amount of the token to transfer (optional). |
| `transaction.token?` | `Address` | The address of the token. `ETH` by default (optional). |
| `transaction.paymasterParams?` | [`PaymasterParams`](./types.md#paymasterparams) | Paymaster parameters (optional). |
| `transaction.overrides?` | `ethers.CallOverrides` | Transaction's overrides which may be used to pass l2 `gasLimit`, `gasPrice`, `value`, etc (optional). |

```ts
async transfer(tx: {
async transfer(transaction: {
to: Address;
amount: BigNumberish;
token?: Address;
overrides?: ethers.CallOverrides;
}): Promise<TransactionResponse>
```

#### Example
#### Examples

Transfer ETH.

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

const PRIVATE_KEY = "<WALLET_PRIVATE_KEY>";

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

const recipient = Wallet.createRandom();

const transferHandle = await wallet.transfer({
to: recipient.address,
amount: ethers.utils.parseEther("0.01"),
amount: ethers.parseEther("0.01"),
});

const tx = await transferHandle.wait();

console.log(`The sum of ${tx.value} ETH was transferred to ${tx.to}`);
```

Transfer ETH using paymaster to facilitate fee payment with an ERC20 token.

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

const PRIVATE_KEY = "<WALLET_PRIVATE_KEY>";
const token = "0x927488F48ffbc32112F1fF721759649A89721F8F"; // Crown token which can be minted for free
const paymaster = "0x13D0D8550769f59aa241a41897D4859c87f7Dd46"; // Paymaster for Crown token

const provider = Provider.getDefaultProvider(types.Network.Sepolia);
const wallet = new Wallet(PRIVATE_KEY, provider);

const recipient = Wallet.createRandom();

const transferHandle = await wallet.transfer({
to: recipient.address,
amount: ethers.parseEther("0.01"),
paymasterParams: utils.getPaymasterParams(paymaster, {
type: "ApprovalBased",
token: token,
minimalAllowance: 1,
innerInput: new Uint8Array(),
}),
});

const tx = await transferHandle.wait();
Expand Down Expand Up @@ -1009,40 +1040,67 @@ L1 network.

#### Inputs

| Parameter | Type | Description |
| ---------------------------- | ---------------------- | ----------------------------------------------------------------------------------------------------- |
| `transaction.token` | `Address` | The address of the token. `ETH` by default. |
| `transaction.amount` | `BigNumberish` | The amount of the token to withdraw. |
| `transaction.to?` | `Address` | The address of the recipient on L1 (optional). |
| `transaction.bridgeAddress?` | `Address` | The address of the bridge contract to be used (optional). |
| `overrides?` | `ethers.CallOverrides` | Transaction's overrides which may be used to pass l2 `gasLimit`, `gasPrice`, `value`, etc (optional). |
| Parameter | Type | Description |
| ------------------------------ | ----------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| `transaction.token` | `Address` | The address of the token. `ETH` by default. |
| `transaction.amount` | `BigNumberish` | The amount of the token to withdraw. |
| `transaction.to?` | `Address` | The address of the recipient on L1 (optional). |
| `transaction.bridgeAddress?` | `Address` | The address of the bridge contract to be used (optional). |
| `transaction.paymasterParams?` | [`PaymasterParams`](./types.md#paymasterparams) | Paymaster parameters (optional). |
| `transaction.overrides?` | `ethers.CallOverrides` | Transaction's overrides which may be used to pass l2 `gasLimit`, `gasPrice`, `value`, etc (optional). |

```ts
async withdraw(transaction: {
token: Address;
amount: BigNumberish;
to?: Address;
bridgeAddress?: Address;
paymasterParams?: PaymasterParams;
overrides?: ethers.CallOverrides;
}): Promise<TransactionResponse>
```

#### Example
#### Examples

Withdraw ETH.

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

const PRIVATE_KEY = "<WALLET_PRIVATE_KEY>";

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

const tokenL2 = "0x6a4Fb925583F7D4dF82de62d98107468aE846FD1";
const tokenWithdrawHandle = await wallet.withdraw({
token: tokenL2,
amount: "10000000",
amount: 10_000_000,
});
```

Withdraw ETH using paymaster to facilitate fee payment with an ERC20 token.

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

const PRIVATE_KEY = "<WALLET_PRIVATE_KEY>";
const token = "0x927488F48ffbc32112F1fF721759649A89721F8F"; // Crown token which can be minted for free
const paymaster = "0x13D0D8550769f59aa241a41897D4859c87f7Dd46"; // Paymaster for Crown token

const provider = Provider.getDefaultProvider(types.Network.Sepolia);
const wallet = new Wallet(PRIVATE_KEY, provider);

const tokenL2 = "0x6a4Fb925583F7D4dF82de62d98107468aE846FD1";
const tokenWithdrawHandle = await wallet.withdraw({
token: tokenL2,
amount: 10_000_000,
paymasterParams: utils.getPaymasterParams(paymaster, {
type: "ApprovalBased",
token: token,
minimalAllowance: 1,
innerInput: new Uint8Array(),
}),
});
```

Expand Down Expand Up @@ -1534,27 +1592,30 @@ But for convenience, the `Wallet` class has `transfer` method, which can transfe

#### Inputs

| Parameter | Type | Description |
| ------------ | ---------------------- | ----------------------------------------------------------------------------------------------------- |
| `tx.to` | `Address` | The address of the recipient. |
| `tx.amount` | `BigNumberish` | The amount of the token to transfer. |
| `token?` | `Address` | The address of the token. `ETH` by default. |
| `overrides?` | `ethers.CallOverrides` | Transaction's overrides which may be used to pass l2 `gasLimit`, `gasPrice`, `value`, etc (optional). |
| Parameter | Type | Description |
| ------------------------------ | ----------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| `transaction.to` | `Address` | The address of the recipient. |
| `transaction.amount` | `BigNumberish` | The amount of the token to transfer. |
| `transaction.token?` | `Address` | The address of the token. `ETH` by default. |
| `transaction.paymasterParams?` | [`PaymasterParams`](./types.md#paymasterparams) | Paymaster parameters (optional). |
| `transaction.overrides?` | `ethers.CallOverrides` | Transaction's overrides which may be used to pass l2 `gasLimit`, `gasPrice`, `value`, etc (optional). |

```ts
async transfer(tx: {
async transfer(transaction: {
to: Address;
amount: BigNumberish;
token?: Address;
paymasterParams?: PaymasterParams;
overrides?: ethers.CallOverrides;
}): Promise<ethers.ContractTransaction>
```

#### Example
#### Examples

Transfer ETH.

```ts
import { Wallet, Web3Provider } from "zksync-ethers";
import { ethers } from "ethers";

const provider = new Web3Provider(window.ethereum);
const signer = provider.getSigner();
Expand All @@ -1567,44 +1628,96 @@ const transferHandle = signer.transfer({
});
```

Transfer ETH using paymaster to facilitate fee payment with an ERC20 token.

```ts
import { Wallet, Web3Provider } from "zksync-ethers";

const token = "0x927488F48ffbc32112F1fF721759649A89721F8F"; // Crown token which can be minted for free
const paymaster = "0x13D0D8550769f59aa241a41897D4859c87f7Dd46"; // Paymaster for Crown token

const provider = new Web3Provider(window.ethereum);
const signer = provider.getSigner();

const recipient = Wallet.createRandom();

const transferHandle = signer.transfer({
to: recipient.address,
amount: ethers.utils.parseEther("0.01"),
paymasterParams: utils.getPaymasterParams(paymaster, {
type: "ApprovalBased",
token: token,
minimalAllowance: 1,
innerInput: new Uint8Array(),
}),
});
```

### `withdraw`

Initiates the withdrawal process which withdraws ETH or any ERC20 token from the associated account on L2 network to the target account on
L1 network.

#### Inputs

| Parameter | Type | Description |
| ---------------------------- | ---------------------- | ----------------------------------------------------------------------------------------------------- |
| `transaction.token` | `Address` | The address of the token. `ETH` by default. |
| `transaction.amount` | `BigNumberish` | The amount of the token to withdraw. |
| `transaction.to?` | `Address` | The address of the recipient on L1 (optional). |
| `transaction.bridgeAddress?` | `Address` | The address of the bridge contract to be used (optional). |
| `overrides?` | `ethers.CallOverrides` | Transaction's overrides which may be used to pass l2 `gasLimit`, `gasPrice`, `value`, etc (optional). |
| Parameter | Type | Description |
| ------------------------------ | ----------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| `transaction.token` | `Address` | The address of the token. `ETH` by default. |
| `transaction.amount` | `BigNumberish` | The amount of the token to withdraw. |
| `transaction.to?` | `Address` | The address of the recipient on L1 (optional). |
| `transaction.bridgeAddress?` | `Address` | The address of the bridge contract to be used (optional). |
| `transaction.paymasterParams?` | [`PaymasterParams`](./types.md#paymasterparams) | Paymaster parameters (optional). |
| `transaction.overrides?` | `ethers.CallOverrides` | Transaction's overrides which may be used to pass l2 `gasLimit`, `gasPrice`, `value`, etc (optional). |

```ts
async withdraw(transaction: {
token: Address;
amount: BigNumberish;
to?: Address;
bridgeAddress?: Address;
paymasterParams?: PaymasterParams;
overrides?: ethers.CallOverrides;
}): Promise<TransactionResponse>
```

#### Example
#### Examples

Withdraw ETH.

```ts
import { Web3Provider } from "zksync-ethers";
import { ethers } from "ethers";

const provider = new Web3Provider(window.ethereum);
const signer = provider.getSigner();

const tokenL2 = "0x6a4Fb925583F7D4dF82de62d98107468aE846FD1";
const tokenWithdrawHandle = await signer.withdraw({
token: tokenL2,
amount: "10000000",
amount: 10_000_000,
});
```

Withdraw ETH using paymaster to facilitate fee payment with an ERC20 token.

```ts
import { Web3Provider } from "zksync-ethers";

const token = "0x927488F48ffbc32112F1fF721759649A89721F8F"; // Crown token which can be minted for free
const paymaster = "0x13D0D8550769f59aa241a41897D4859c87f7Dd46"; // Paymaster for Crown token

const provider = new Web3Provider(window.ethereum);
const signer = provider.getSigner();

const tokenL2 = "0x6a4Fb925583F7D4dF82de62d98107468aE846FD1";
const tokenWithdrawHandle = await signer.withdraw({
token: tokenL2,
amount: 10_000_000,
paymasterParams: utils.getPaymasterParams(paymaster, {
type: "ApprovalBased",
token: token,
minimalAllowance: 1,
innerInput: new Uint8Array(),
}),
});
```

Expand Down
Loading

0 comments on commit 48ef1cf

Please sign in to comment.