@@ -593,39 +593,70 @@ For convenience, the `Wallet` class has `transfer` method, which can transfer `E
593593
594594#### Inputs
595595
596- | Parameter | Type | Description |
597- | ------------ | ---------------------- | ----------------------------------------------------------------------------------------------------- |
598- | ` tx.to ` | ` Address ` | The address of the recipient. |
599- | ` tx.amount ` | ` BigNumberish ` | The amount of the token to transfer (optional). |
600- | ` tx.token? ` | ` Address ` | The address of the token. ` ETH ` by default (optional). |
601- | ` overrides? ` | ` ethers.CallOverrides ` | Transaction's overrides which may be used to pass l2 ` gasLimit ` , ` gasPrice ` , ` value ` , etc (optional). |
596+ | Parameter | Type | Description |
597+ | ------------------------------ | ----------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
598+ | ` transaction.to ` | ` Address ` | The address of the recipient. |
599+ | ` transaction.amount ` | ` BigNumberish ` | The amount of the token to transfer (optional). |
600+ | ` transaction.token? ` | ` Address ` | The address of the token. ` ETH ` by default (optional). |
601+ | ` transaction.paymasterParams? ` | [ ` PaymasterParams ` ] ( ./types.md#paymasterparams ) | Paymaster parameters (optional). |
602+ | ` transaction.overrides? ` | ` ethers.CallOverrides ` | Transaction's overrides which may be used to pass l2 ` gasLimit ` , ` gasPrice ` , ` value ` , etc (optional). |
602603
603604``` ts
604- async transfer (tx : {
605+ async transfer (transaction : {
605606 to: Address ;
606607 amount : BigNumberish ;
607608 token ?: Address ;
608609 overrides ?: ethers .CallOverrides ;
609610}): Promise < TransactionResponse >
610611```
611612
612- #### Example
613+ #### Examples
614+
615+ Transfer ETH.
613616
614617``` ts
615618import { Wallet , Provider , utils } from " zksync-ethers" ;
616- import { ethers } from " ethers" ;
617619
618620const PRIVATE_KEY = " <WALLET_PRIVATE_KEY>" ;
619621
620622const provider = Provider .getDefaultProvider (types .Network .Sepolia );
621- const ethProvider = ethers .getDefaultProvider (" sepolia" );
622- const wallet = new Wallet (PRIVATE_KEY , provider , ethProvider );
623+ const wallet = new Wallet (PRIVATE_KEY , provider );
623624
624625const recipient = Wallet .createRandom ();
625626
626627const transferHandle = await wallet .transfer ({
627628 to: recipient .address ,
628- amount: ethers .utils .parseEther (" 0.01" ),
629+ amount: ethers .parseEther (" 0.01" ),
630+ });
631+
632+ const tx = await transferHandle .wait ();
633+
634+ console .log (` The sum of ${tx .value } ETH was transferred to ${tx .to } ` );
635+ ```
636+
637+ Transfer ETH using paymaster to facilitate fee payment with an ERC20 token.
638+
639+ ``` ts
640+ import { Wallet , Provider , utils } from " zksync-ethers" ;
641+
642+ const PRIVATE_KEY = " <WALLET_PRIVATE_KEY>" ;
643+ const token = " 0x927488F48ffbc32112F1fF721759649A89721F8F" ; // Crown token which can be minted for free
644+ const paymaster = " 0x13D0D8550769f59aa241a41897D4859c87f7Dd46" ; // Paymaster for Crown token
645+
646+ const provider = Provider .getDefaultProvider (types .Network .Sepolia );
647+ const wallet = new Wallet (PRIVATE_KEY , provider );
648+
649+ const recipient = Wallet .createRandom ();
650+
651+ const transferHandle = await wallet .transfer ({
652+ to: recipient .address ,
653+ amount: ethers .parseEther (" 0.01" ),
654+ paymasterParams: utils .getPaymasterParams (paymaster , {
655+ type: " ApprovalBased" ,
656+ token: token ,
657+ minimalAllowance: 1 ,
658+ innerInput: new Uint8Array (),
659+ }),
629660});
630661
631662const tx = await transferHandle .wait ();
@@ -1009,40 +1040,67 @@ L1 network.
10091040
10101041#### Inputs
10111042
1012- | Parameter | Type | Description |
1013- | ---------------------------- | ---------------------- | ----------------------------------------------------------------------------------------------------- |
1014- | ` transaction.token ` | ` Address ` | The address of the token. ` ETH ` by default. |
1015- | ` transaction.amount ` | ` BigNumberish ` | The amount of the token to withdraw. |
1016- | ` transaction.to? ` | ` Address ` | The address of the recipient on L1 (optional). |
1017- | ` transaction.bridgeAddress? ` | ` Address ` | The address of the bridge contract to be used (optional). |
1018- | ` overrides? ` | ` ethers.CallOverrides ` | Transaction's overrides which may be used to pass l2 ` gasLimit ` , ` gasPrice ` , ` value ` , etc (optional). |
1043+ | Parameter | Type | Description |
1044+ | ------------------------------ | ----------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
1045+ | ` transaction.token ` | ` Address ` | The address of the token. ` ETH ` by default. |
1046+ | ` transaction.amount ` | ` BigNumberish ` | The amount of the token to withdraw. |
1047+ | ` transaction.to? ` | ` Address ` | The address of the recipient on L1 (optional). |
1048+ | ` transaction.bridgeAddress? ` | ` Address ` | The address of the bridge contract to be used (optional). |
1049+ | ` transaction.paymasterParams? ` | [ ` PaymasterParams ` ] ( ./types.md#paymasterparams ) | Paymaster parameters (optional). |
1050+ | ` transaction.overrides? ` | ` ethers.CallOverrides ` | Transaction's overrides which may be used to pass l2 ` gasLimit ` , ` gasPrice ` , ` value ` , etc (optional). |
10191051
10201052``` ts
10211053async withdraw (transaction : {
10221054 token: Address ;
10231055 amount : BigNumberish ;
10241056 to ?: Address ;
10251057 bridgeAddress ?: Address ;
1058+ paymasterParams ?: PaymasterParams ;
10261059 overrides ?: ethers .CallOverrides ;
10271060}): Promise < TransactionResponse >
10281061```
10291062
1030- #### Example
1063+ #### Examples
1064+
1065+ Withdraw ETH.
10311066
10321067``` ts
10331068import { Wallet , Provider , utils } from " zksync-ethers" ;
1034- import { ethers } from " ethers" ;
10351069
10361070const PRIVATE_KEY = " <WALLET_PRIVATE_KEY>" ;
10371071
10381072const provider = Provider .getDefaultProvider (types .Network .Sepolia );
1039- const ethProvider = ethers .getDefaultProvider (" sepolia" );
1040- const wallet = new Wallet (PRIVATE_KEY , provider , ethProvider );
1073+ const wallet = new Wallet (PRIVATE_KEY , provider );
10411074
10421075const tokenL2 = " 0x6a4Fb925583F7D4dF82de62d98107468aE846FD1" ;
10431076const tokenWithdrawHandle = await wallet .withdraw ({
10441077 token: tokenL2 ,
1045- amount: " 10000000" ,
1078+ amount: 10_000_000 ,
1079+ });
1080+ ```
1081+
1082+ Withdraw ETH using paymaster to facilitate fee payment with an ERC20 token.
1083+
1084+ ``` ts
1085+ import { Wallet , Provider , utils } from " zksync-ethers" ;
1086+
1087+ const PRIVATE_KEY = " <WALLET_PRIVATE_KEY>" ;
1088+ const token = " 0x927488F48ffbc32112F1fF721759649A89721F8F" ; // Crown token which can be minted for free
1089+ const paymaster = " 0x13D0D8550769f59aa241a41897D4859c87f7Dd46" ; // Paymaster for Crown token
1090+
1091+ const provider = Provider .getDefaultProvider (types .Network .Sepolia );
1092+ const wallet = new Wallet (PRIVATE_KEY , provider );
1093+
1094+ const tokenL2 = " 0x6a4Fb925583F7D4dF82de62d98107468aE846FD1" ;
1095+ const tokenWithdrawHandle = await wallet .withdraw ({
1096+ token: tokenL2 ,
1097+ amount: 10_000_000 ,
1098+ paymasterParams: utils .getPaymasterParams (paymaster , {
1099+ type: " ApprovalBased" ,
1100+ token: token ,
1101+ minimalAllowance: 1 ,
1102+ innerInput: new Uint8Array (),
1103+ }),
10461104});
10471105```
10481106
@@ -1534,27 +1592,30 @@ But for convenience, the `Wallet` class has `transfer` method, which can transfe
15341592
15351593#### Inputs
15361594
1537- | Parameter | Type | Description |
1538- | ------------ | ---------------------- | ----------------------------------------------------------------------------------------------------- |
1539- | ` tx.to ` | ` Address ` | The address of the recipient. |
1540- | ` tx.amount ` | ` BigNumberish ` | The amount of the token to transfer. |
1541- | ` token? ` | ` Address ` | The address of the token. ` ETH ` by default. |
1542- | ` overrides? ` | ` ethers.CallOverrides ` | Transaction's overrides which may be used to pass l2 ` gasLimit ` , ` gasPrice ` , ` value ` , etc (optional). |
1595+ | Parameter | Type | Description |
1596+ | ------------------------------ | ----------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
1597+ | ` transaction.to ` | ` Address ` | The address of the recipient. |
1598+ | ` transaction.amount ` | ` BigNumberish ` | The amount of the token to transfer. |
1599+ | ` transaction.token? ` | ` Address ` | The address of the token. ` ETH ` by default. |
1600+ | ` transaction.paymasterParams? ` | [ ` PaymasterParams ` ] ( ./types.md#paymasterparams ) | Paymaster parameters (optional). |
1601+ | ` transaction.overrides? ` | ` ethers.CallOverrides ` | Transaction's overrides which may be used to pass l2 ` gasLimit ` , ` gasPrice ` , ` value ` , etc (optional). |
15431602
15441603``` ts
1545- async transfer (tx : {
1604+ async transfer (transaction : {
15461605 to: Address ;
15471606 amount : BigNumberish ;
15481607 token ?: Address ;
1608+ paymasterParams ?: PaymasterParams ;
15491609 overrides ?: ethers .CallOverrides ;
15501610}): Promise < ethers .ContractTransaction >
15511611```
15521612
1553- #### Example
1613+ #### Examples
1614+
1615+ Transfer ETH.
15541616
15551617``` ts
15561618import { Wallet , Web3Provider } from " zksync-ethers" ;
1557- import { ethers } from " ethers" ;
15581619
15591620const provider = new Web3Provider (window .ethereum );
15601621const signer = provider .getSigner ();
@@ -1567,44 +1628,96 @@ const transferHandle = signer.transfer({
15671628});
15681629```
15691630
1631+ Transfer ETH using paymaster to facilitate fee payment with an ERC20 token.
1632+
1633+ ``` ts
1634+ import { Wallet , Web3Provider } from " zksync-ethers" ;
1635+
1636+ const token = " 0x927488F48ffbc32112F1fF721759649A89721F8F" ; // Crown token which can be minted for free
1637+ const paymaster = " 0x13D0D8550769f59aa241a41897D4859c87f7Dd46" ; // Paymaster for Crown token
1638+
1639+ const provider = new Web3Provider (window .ethereum );
1640+ const signer = provider .getSigner ();
1641+
1642+ const recipient = Wallet .createRandom ();
1643+
1644+ const transferHandle = signer .transfer ({
1645+ to: recipient .address ,
1646+ amount: ethers .utils .parseEther (" 0.01" ),
1647+ paymasterParams: utils .getPaymasterParams (paymaster , {
1648+ type: " ApprovalBased" ,
1649+ token: token ,
1650+ minimalAllowance: 1 ,
1651+ innerInput: new Uint8Array (),
1652+ }),
1653+ });
1654+ ```
1655+
15701656### ` withdraw `
15711657
15721658Initiates the withdrawal process which withdraws ETH or any ERC20 token from the associated account on L2 network to the target account on
15731659L1 network.
15741660
15751661#### Inputs
15761662
1577- | Parameter | Type | Description |
1578- | ---------------------------- | ---------------------- | ----------------------------------------------------------------------------------------------------- |
1579- | ` transaction.token ` | ` Address ` | The address of the token. ` ETH ` by default. |
1580- | ` transaction.amount ` | ` BigNumberish ` | The amount of the token to withdraw. |
1581- | ` transaction.to? ` | ` Address ` | The address of the recipient on L1 (optional). |
1582- | ` transaction.bridgeAddress? ` | ` Address ` | The address of the bridge contract to be used (optional). |
1583- | ` overrides? ` | ` ethers.CallOverrides ` | Transaction's overrides which may be used to pass l2 ` gasLimit ` , ` gasPrice ` , ` value ` , etc (optional). |
1663+ | Parameter | Type | Description |
1664+ | ------------------------------ | ----------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
1665+ | ` transaction.token ` | ` Address ` | The address of the token. ` ETH ` by default. |
1666+ | ` transaction.amount ` | ` BigNumberish ` | The amount of the token to withdraw. |
1667+ | ` transaction.to? ` | ` Address ` | The address of the recipient on L1 (optional). |
1668+ | ` transaction.bridgeAddress? ` | ` Address ` | The address of the bridge contract to be used (optional). |
1669+ | ` transaction.paymasterParams? ` | [ ` PaymasterParams ` ] ( ./types.md#paymasterparams ) | Paymaster parameters (optional). |
1670+ | ` transaction.overrides? ` | ` ethers.CallOverrides ` | Transaction's overrides which may be used to pass l2 ` gasLimit ` , ` gasPrice ` , ` value ` , etc (optional). |
15841671
15851672``` ts
15861673async withdraw (transaction : {
15871674 token: Address ;
15881675 amount : BigNumberish ;
15891676 to ?: Address ;
15901677 bridgeAddress ?: Address ;
1678+ paymasterParams ?: PaymasterParams ;
15911679 overrides ?: ethers .CallOverrides ;
15921680}): Promise < TransactionResponse >
15931681```
15941682
1595- #### Example
1683+ #### Examples
1684+
1685+ Withdraw ETH.
15961686
15971687``` ts
15981688import { Web3Provider } from " zksync-ethers" ;
1599- import { ethers } from " ethers" ;
16001689
16011690const provider = new Web3Provider (window .ethereum );
16021691const signer = provider .getSigner ();
16031692
16041693const tokenL2 = " 0x6a4Fb925583F7D4dF82de62d98107468aE846FD1" ;
16051694const tokenWithdrawHandle = await signer .withdraw ({
16061695 token: tokenL2 ,
1607- amount: " 10000000" ,
1696+ amount: 10_000_000 ,
1697+ });
1698+ ```
1699+
1700+ Withdraw ETH using paymaster to facilitate fee payment with an ERC20 token.
1701+
1702+ ``` ts
1703+ import { Web3Provider } from " zksync-ethers" ;
1704+
1705+ const token = " 0x927488F48ffbc32112F1fF721759649A89721F8F" ; // Crown token which can be minted for free
1706+ const paymaster = " 0x13D0D8550769f59aa241a41897D4859c87f7Dd46" ; // Paymaster for Crown token
1707+
1708+ const provider = new Web3Provider (window .ethereum );
1709+ const signer = provider .getSigner ();
1710+
1711+ const tokenL2 = " 0x6a4Fb925583F7D4dF82de62d98107468aE846FD1" ;
1712+ const tokenWithdrawHandle = await signer .withdraw ({
1713+ token: tokenL2 ,
1714+ amount: 10_000_000 ,
1715+ paymasterParams: utils .getPaymasterParams (paymaster , {
1716+ type: " ApprovalBased" ,
1717+ token: token ,
1718+ minimalAllowance: 1 ,
1719+ innerInput: new Uint8Array (),
1720+ }),
16081721});
16091722```
16101723
0 commit comments