@@ -28,14 +28,40 @@ For this purpose, use the `createAccount` or `create2Account` methods of the dep
2828system contract, rather than the general ` create ` or ` create2 ` methods, which are
2929used for contracts not intended to act as accounts.
3030
31- #### Example Using ` zksync-ethers ` SDK (v5)
31+ #### Example Using ` zksync-ethers ` SDK (v6)
32+
33+ You can use the [ ` ECDSASmartAccount ` ] ( https://sdk.zksync.io/js/ethers/api/v6/accounts/smartaccount-factories#ecdsasmartaccount ) or
34+ [ ` MultisigECDSASmartAccount ` ] ( https://sdk.zksync.io/js/ethers/api/v6/accounts/smartaccount-factories#multisigecdsasmartaccount )
35+ to create a standard smart account or multisig smart account.
3236
3337``` ts
34- import { ContractFactory } from " zksync-ethers" ;
38+ import { types , ECDSASmartAccount , MultisigECDSASmartAccount , } from " zksync-ethers" ;
39+
40+ const account = ECDSASmartAccount .create (ADDRESS , PRIVATE_KEY , provider );
41+ const multisigAccount = MultisigECDSASmartAccount .create (multisigAddress , [PRIVATE_KEY1 , PRIVATE_KEY2 ], provider );
42+ ```
43+
44+ You can also deploy with custom factory and account contracts using the example below.
3545
36- const contractFactory = new ContractFactory (abi , bytecode , initiator , " createAccount" );
37- const aa = await contractFactory .deploy (... args );
38- await aa .deployed ();
46+ ``` ts
47+ async function deployAAFactory(hre : HardhatRuntimeEnvironment ) {
48+ const deployer = hre .deployer ;
49+ // the factory contract
50+ const factoryArtifact = await deployer .loadArtifact (' AAFactory' );
51+ // the account contract
52+ const aaArtifact = await deployer .loadArtifact (' Account' );
53+
54+ const factory = await deployer .deploy (
55+ factoryArtifact ,
56+ [utils .hashBytecode (aaArtifact .bytecode )],
57+ undefined ,
58+ undefined ,
59+ [aaArtifact .bytecode ]
60+ );
61+ const factoryAddress = await factory .getAddress ();
62+ console .log (` AA factory address: ${factoryAddress } ` );
63+ return factory ;
64+ }
3965```
4066
4167### Verification Step Limitations
@@ -65,19 +91,57 @@ Currently, only EIP712 formatted transactions are supported for sending from cus
6591accounts. Transactions must specify the ` from ` field as the account's address and
6692include a ` customSignature ` in the ` customData ` .
6793
68- #### Example Transaction Submission
94+ #### Example Transaction Submission With a Private Key
95+
96+ To send a transaction using the private key of a deployed smart account, you can use the
97+ [ ` SmartAccount ` ] ( https://sdk.zksync.io/js/ethers/api/v6/accounts/smartaccount#sendtransaction ) class from ` zksync-ethers ` :
98+
99+ ``` ts
100+ import { SmartAccount , Provider , types } from " zksync-ethers" ;
101+ import { parseEther } from " ethers" ;
102+
103+ const provider = Provider .getDefaultProvider (types .Network .Sepolia );
104+ const account = new SmartAccount ({ address: ADDRESS , secret: PRIVATE_KEY }, provider );
105+
106+ const signedTx = await account .sendTransaction ({
107+ to: recipientAddress ,
108+ value: parseEther (amount ),
109+ });
110+ ```
111+
112+ #### Example Transaction Submission Without a Private Key
113+
114+ You can also manually add a custom signature to a transaction,
115+ like in the example below.
69116
70117``` ts
71- import { utils } from " zksync-ethers" ;
118+ import { types , Provider } from " zksync-ethers" ;
119+ import { parseEther , AbiCoder } from " ethers" ;
120+
121+ const provider = new Provider (rpcUrl );
122+ let tx: types .TransactionLike = {
123+ to: recipientAddress ,
124+ value: parseEther (amount ),
125+ gasPrice: await provider .getGasPrice (),
126+ gasLimit: BigInt (20000000 ),
127+ chainId: (await provider .getNetwork ()).chainId ,
128+ nonce: await provider .getTransactionCount (aaAddress ),
129+ };
130+
131+ const abiCoder = new AbiCoder ();
132+ const aaSignature = abiCoder .encode (
133+ [' string' , ' string' ],
134+ [' hello' , ' world' ]
135+ );
72136
73- // Here, `tx` is a `TransactionRequest` object from `zksync-ethers` SDK.
74- // `zksyncProvider` is the `Provider` object from `zksync-ethers` SDK connected to the ZKSync network.
75137tx .from = aaAddress ;
138+ tx .type = 113 ;
76139tx .customData = {
77140 ... tx .customData ,
78141 customSignature: aaSignature ,
79142};
80- const serializedTx = utils .serialize ({ ... tx });
81-
82- const sentTx = await zksyncProvider .sendTransaction (serializedTx );
143+ const sentTx = await provider .broadcastTransaction (
144+ types .Transaction .from (tx ).serialized
145+ );
146+ await sentTx .wait ();
83147```
0 commit comments