@tetherto/wdk-wallet-evm-erc-4337 1.0.0-beta.2 → 1.0.0-beta.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,740 +1,153 @@
1
1
  # @tetherto/wdk-wallet-evm-erc-4337
2
2
 
3
- **Note**: This package is currently in beta. Please test thoroughly in development environments before using in production.
4
-
5
- A simple and secure package to manage ERC-4337 compliant wallets for EVM-compatible blockchains. This package provides a clean API for creating, managing, and interacting with account abstraction wallets using BIP-39 seed phrases and EVM-specific derivation paths.
6
-
7
- ## 🔍 About WDK
8
-
9
- This module is part of the [**WDK (Wallet Development Kit)**](https://wallet.tether.io/) project, which empowers developers to build secure, non-custodial wallets with unified blockchain access, stateless architecture, and complete user control.
3
+ [![npm version](https://img.shields.io/npm/v/%40tetherto%2Fwdk-wallet-evm-erc-4337?style=flat-square)](https://www.npmjs.com/package/@tetherto/wdk-wallet-evm-erc-4337)
4
+ [![npm downloads](https://img.shields.io/npm/dw/%40tetherto%2Fwdk-wallet-evm-erc-4337?style=flat-square)](https://www.npmjs.com/package/@tetherto/wdk-wallet-evm-erc-4337)
5
+ [![license](https://img.shields.io/npm/l/%40tetherto%2Fwdk-wallet-evm-erc-4337?style=flat-square)](https://github.com/tetherto/wdk-wallet-evm-erc-4337/blob/main/LICENSE)
6
+ [![docs](https://img.shields.io/badge/docs-docs.wdk.tether.io-0A66C2?style=flat-square)](https://docs.wdk.tether.io/sdk/wallet-modules/wallet-evm-erc-4337)
10
7
 
11
- For detailed documentation about the complete WDK ecosystem, visit [docs.wallet.tether.io](https://docs.wallet.tether.io).
8
+ **Note**: This package is currently in beta. Please test thoroughly in development environments before using in production.
12
9
 
13
- ## 🌟 Features
10
+ An ERC-4337 wallet module for EVM-compatible blockchains in WDK (Wallet Development Kit) by Tether. This package provides a clean API for creating, managing, and interacting with account abstraction wallets using BIP-39 seed phrases and EVM-specific derivation paths.
14
11
 
15
- - **EVM Derivation Paths**: Support for BIP-44 standard derivation paths for Ethereum (m/44'/60')
16
- - **Multi-Account Management**: Create and manage multiple account abstraction wallets from a single seed phrase
17
- - **ERC-4337 Support**: Full implementation of ERC-4337 account abstraction standard
18
- - **UserOperation Management**: Create and send UserOperations through bundlers
19
- - **ERC20 Support**: Query native token and ERC20 token balances using smart contract interactions
12
+ ## About WDK
20
13
 
21
- ## ⬇️ Installation
14
+ This module is part of the [**WDK (Wallet Development Kit)**](https://docs.wdk.tether.io/) project, which empowers developers to build secure, non-custodial wallets with unified blockchain access, stateless architecture, and complete user control.
22
15
 
23
- To install the `@tetherto/wdk-wallet-evm-erc-4337` package, follow these instructions:
16
+ For detailed documentation about the complete WDK ecosystem, visit [docs.wdk.tether.io](https://docs.wdk.tether.io).
24
17
 
25
- You can install it using npm:
18
+ ## Installation
26
19
 
27
20
  ```bash
28
21
  npm install @tetherto/wdk-wallet-evm-erc-4337
29
22
  ```
30
23
 
31
- ## 🚀 Quick Start
32
-
33
- ### Importing from `@tetherto/wdk-wallet-evm-erc-4337`
34
-
35
- ### Creating a New Wallet
36
-
37
- ```javascript
38
- import WalletManagerEvmErc4337, {
39
- WalletAccountEvmErc4337,
40
- WalletAccountReadOnlyEvmErc4337
41
- } from '@tetherto/wdk-wallet-evm-erc-4337'
42
-
43
- // Use a BIP-39 seed phrase (replace with your own secure phrase)
44
- const seedPhrase = 'test only example nut use this real life secret phrase must random'
45
-
46
- // Create wallet manager with ERC-4337 config
47
- const wallet = new WalletManagerEvmErc4337(seedPhrase, {
48
- // Required parameters
49
- chainId: 1, // Ethereum Mainnet
50
- provider: 'https://eth-mainnet.g.alchemy.com/v2/your-api-key', // RPC endpoint
51
- bundlerUrl: 'https://api.stackup.sh/v1/bundler/your-api-key', // ERC-4337 bundler
52
- entryPointAddress: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', // EntryPoint contract
53
- factoryAddress: '0x3F51274DfD7c51Ac1C4C798B21f295611560d511', // Account factory contract
54
-
55
- // Optional parameters
56
- paymasterUrl: 'https://api.paymaster.com', // Optional: Paymaster service URL
57
- transferMaxFee: 100000000000000 // Optional: Maximum fee in wei
58
- })
59
-
60
- // Get a full access account
61
- const account = await wallet.getAccount(0)
62
-
63
- // Convert to a read-only account
64
- const readOnlyAccount = await account.toReadOnlyAccount()
65
- ```
66
-
67
- ### Managing Multiple Accounts
24
+ ## Quick Start
68
25
 
69
26
  ```javascript
70
27
  import WalletManagerEvmErc4337 from '@tetherto/wdk-wallet-evm-erc-4337'
71
28
 
72
- // Assume wallet is already created
73
- // Get the first account (index 0)
74
- const account = await wallet.getAccount(0)
75
- const address = await account.getAddress()
76
- console.log('Account 0 address:', address)
77
-
78
- // Get the second account (index 1)
79
- const account1 = await wallet.getAccount(1)
80
- const address1 = await account1.getAddress()
81
- console.log('Account 1 address:', address1)
82
-
83
- // Get account by custom derivation path
84
- // Full path will be m/44'/60'/0'/0/5
85
- const customAccount = await wallet.getAccountByPath("0'/0/5")
86
- const customAddress = await customAccount.getAddress()
87
- console.log('Custom account address:', customAddress)
88
-
89
- // Note: All addresses are checksummed Ethereum addresses (0x...)
90
- // All accounts inherit the provider configuration from the wallet manager
91
- ```
92
-
93
- ### Checking Balances
94
-
95
- #### Owned Account
96
-
97
- For accounts where you have the seed phrase and full access:
98
-
99
- ```javascript
100
- import WalletManagerEvmErc4337 from '@tetherto/wdk-wallet-evm-erc-4337'
101
-
102
- // Assume wallet and account are already created
103
- // Get native token balance (in wei)
104
- const balance = await account.getBalance()
105
- console.log('Native balance:', balance, 'wei') // 1 ETH = 1000000000000000000 wei
106
-
107
- // Get ERC20 token balance
108
- const tokenContract = '0x...'; // ERC20 contract address
109
-
110
- const tokenBalance = await account.getTokenBalance(tokenContract);
111
- console.log('Token balance:', tokenBalance);
112
-
113
- // Note: Provider is required for balance checks
114
- // Make sure wallet was created with a provider configuration
115
- ```
116
-
117
- #### Read-Only Account
118
-
119
- For addresses where you don't have the seed phrase:
120
-
121
- ```javascript
122
- import { WalletAccountReadOnlyEvmErc4337 } from '@tetherto/wdk-wallet-evm-erc-4337'
123
-
124
- // Create a read-only account
125
- const readOnlyAccount = new WalletAccountReadOnlyEvmErc4337('0x636e9c21f27d9401ac180666bf8DC0D3FcEb0D24', { // Smart contract wallet address
126
- provider: 'https://eth-mainnet.g.alchemy.com/v2/your-api-key',
127
- bundlerUrl: 'https://api.stackup.sh/v1/bundler/your-api-key',
128
- entryPointAddress: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789'
129
- })
130
-
131
- // Check native token balance
132
- const balance = await readOnlyAccount.getBalance()
133
- console.log('Native balance:', balance, 'wei')
134
-
135
- // Check ERC20 token balance using contract
136
- const tokenBalance = await readOnlyAccount.getTokenBalance('0xdAC17F958D2ee523a2206206994597C13D831ec7') // USDT contract address
137
- console.log('Token balance:', tokenBalance)
138
-
139
- // Note: ERC20 balance checks use the standard balanceOf(address) function
140
- // Make sure the contract address is correct and implements the ERC20 standard
141
- ```
142
-
143
- ### Sending Transactions
144
-
145
- Send transactions using UserOperations through the bundler service. All transactions are handled via the EntryPoint contract.
146
-
147
- ```javascript
148
- // Send native tokens via UserOperation
149
- const result = await account.sendTransaction({
150
- to: '0x636e9c21f27d9401ac180666bf8DC0D3FcEb0D24', // Recipient address
151
- value: 1000000000000000000n, // 1 ETH in wei
152
- data: '0x', // Optional: transaction data
153
- })
154
- console.log('UserOperation hash:', result.hash)
155
- console.log('Transaction fee:', result.fee, 'wei')
156
-
157
- // Get transaction fee estimate
158
- const quote = await account.quoteSendTransaction({
159
- to: '0x636e9c21f27d9401ac180666bf8DC0D3FcEb0D24',
160
- value: 1000000000000000000n
161
- });
162
- console.log('Estimated fee:', quote.fee, 'wei');
163
-
164
- // Note: Fees are calculated by the bundler and may include paymaster costs
165
- ```
166
-
167
- ### Token Transfers
168
-
169
- Transfer ERC20 tokens using UserOperations. Uses standard ERC20 `transfer` function.
170
-
171
- ```javascript
172
- // Transfer ERC20 tokens via UserOperation
173
- const transferResult = await account.transfer({
174
- token: '0xdAC17F958D2ee523a2206206994597C13D831ec7', // USDT contract address
175
- recipient: '0x636e9c21f27d9401ac180666bf8DC0D3FcEb0D24', // Recipient's address
176
- amount: 1000000n // Amount in token's base units (1 USDT = 1000000 for 6 decimals)
177
- });
178
- console.log('UserOperation hash:', transferResult.hash);
179
- console.log('Transfer fee:', transferResult.fee, 'wei');
180
-
181
- // Quote token transfer fee
182
- const transferQuote = await account.quoteTransfer({
183
- token: '0xdAC17F958D2ee523a2206206994597C13D831ec7', // USDT contract address
184
- recipient: '0x636e9c21f27d9401ac180666bf8DC0D3FcEb0D24', // Recipient's address
185
- amount: 1000000n // Amount in token's base units
186
- })
187
- console.log('Transfer fee estimate:', transferQuote.fee, 'wei')
188
- ```
189
-
190
- ### Message Signing and Verification
191
-
192
- Sign and verify messages using `WalletAccountEvmErc4337`.
193
-
194
- ```javascript
195
- // Sign a message
196
- const message = 'Hello, Account Abstraction!'
197
- const signature = await account.sign(message)
198
- console.log('Signature:', signature)
199
-
200
- // Verify a signature
201
- const isValid = await account.verify(message, signature)
202
- console.log('Signature valid:', isValid)
203
- ```
204
-
205
- ### Fee Management
206
-
207
- Retrieve current fee rates using `WalletManagerEvmErc4337`. Uses bundler service for fee estimation.
208
-
209
- ```javascript
210
- // Get current bundler fee rates
211
- const feeRates = await wallet.getFeeRates();
212
- console.log('Normal fee rate:', feeRates.normal, 'wei'); // Base bundler fee
213
- console.log('Fast fee rate:', feeRates.fast, 'wei'); // Priority bundler fee
214
- ```
215
-
216
- ### Memory Management
217
-
218
- Clear sensitive data from memory using `dispose` methods in `WalletAccountEvmErc4337` and `WalletManagerEvmErc4337`.
219
-
220
- ```javascript
221
- // Dispose wallet accounts to clear private keys from memory
222
- account.dispose()
223
-
224
- // Dispose entire wallet manager
225
- wallet.dispose()
226
- ```
227
-
228
- ## 📚 API Reference
229
-
230
- ### Table of Contents
231
-
232
- | Class | Description | Methods |
233
- |-------|-------------|---------|
234
- | [WalletManagerEvmErc4337](#walletmanagerevmerc4337) | Main class for managing ERC-4337 wallets. Extends `WalletManager` from `@tetherto/wdk-wallet`. | [Constructor](#constructor), [Methods](#methods) |
235
- | [WalletAccountEvmErc4337](#walletaccountevmerc4337) | Individual ERC-4337 wallet account implementation. Extends `WalletAccountReadOnlyEvmErc4337` and implements `IWalletAccount` from `@tetherto/wdk-wallet`. | [Constructor](#constructor-1), [Methods](#methods-1), [Properties](#properties) |
236
- | [WalletAccountReadOnlyEvmErc4337](#walletaccountreadonlyevmerc4337) | Read-only ERC-4337 wallet account. Extends `WalletAccountReadOnly` from `@tetherto/wdk-wallet`. | [Constructor](#constructor-2), [Methods](#methods-2) |
29
+ const seedPhrase = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about'
237
30
 
238
- ### WalletManagerEvmErc4337
239
-
240
- The main class for managing ERC-4337 compliant wallets.
241
- Extends `WalletManager` from `@tetherto/wdk-wallet`.
242
-
243
- #### Constructor
244
-
245
- ```javascript
246
- new WalletManagerEvmErc4337(seed, config)
247
- ```
248
-
249
- **Parameters:**
250
- - `seed` (string | Uint8Array): BIP-39 mnemonic seed phrase or seed bytes
251
- - `config` (object): Configuration object
252
- - `provider` (string | Eip1193Provider): RPC endpoint URL or EIP-1193 provider instance
253
- - `bundlerUrl` (string): URL of the ERC-4337 bundler service
254
- - `entryPointAddress` (string): Address of the EntryPoint contract
255
- - `factoryAddress` (string): Address of the account factory contract
256
- - `chainId` (number): Chain ID of the target network
257
- - `paymasterUrl` (string, optional): URL of the paymaster service
258
- - `transferMaxFee` (number | bigint, optional): Maximum fee amount for transfer operations (in wei)
259
-
260
- **Example:**
261
- ```javascript
262
31
  const wallet = new WalletManagerEvmErc4337(seedPhrase, {
263
- provider: 'https://eth-mainnet.g.alchemy.com/v2/your-api-key',
264
- bundlerUrl: 'https://api.stackup.sh/v1/bundler/your-api-key',
265
- entryPointAddress: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789',
266
- factoryAddress: '0x3F51274DfD7c51Ac1C4C798B21f295611560d511',
267
- chainId: 1,
268
- transferMaxFee: '100000000000000' // Maximum fee in wei
32
+ chainId: 11155111, // Sepolia
33
+ provider: 'https://sepolia.drpc.org',
34
+ bundlerUrl: 'https://api.pimlico.io/v2/sepolia/rpc?apikey=YOUR_KEY',
35
+ safeModulesVersion: '0.3.0',
36
+ useNativeCoins: true,
269
37
  })
270
- ```
271
-
272
- #### Methods
273
-
274
- | Method | Description | Returns |
275
- |--------|-------------|---------|
276
- | `getAccount(index)` | Returns a wallet account at the specified index | `Promise<WalletAccountEvmErc4337>` |
277
- | `getAccountByPath(path)` | Returns a wallet account at the specified BIP-44 derivation path | `Promise<WalletAccountEvmErc4337>` |
278
- | `getFeeRates()` | Returns current bundler fee rates for UserOperations | `Promise<{normal: bigint, fast: bigint}>` |
279
- | `dispose()` | Disposes all wallet accounts, clearing private keys from memory | `void` |
280
-
281
- ##### `getAccount(index)`
282
- Returns an ERC-4337 wallet account at the specified index using BIP-44 derivation.
283
-
284
- **Parameters:**
285
- - `index` (number, optional): The index of the account to get (default: 0)
286
-
287
- **Returns:** `Promise<WalletAccountEvmErc4337>` - The ERC-4337 wallet account
288
38
 
289
- **Example:**
290
- ```javascript
291
39
  const account = await wallet.getAccount(0)
292
40
  const address = await account.getAddress()
293
41
  console.log('Smart account address:', address)
294
- ```
295
-
296
- ##### `getAccountByPath(path)`
297
- Returns an ERC-4337 wallet account at the specified BIP-44 derivation path.
298
-
299
- **Parameters:**
300
- - `path` (string): The derivation path (e.g., "0'/0/0", "1'/0/5")
301
42
 
302
- **Returns:** `Promise<WalletAccountEvmErc4337>` - The ERC-4337 wallet account
303
-
304
- **Example:**
305
- ```javascript
306
- const account = await wallet.getAccountByPath("0'/0/1")
307
- const address = await account.getAddress()
308
- console.log('Smart account address:', address)
309
- ```
310
-
311
- ##### `getFeeRates()`
312
- Returns current bundler fee rates for ERC-4337 UserOperations.
313
-
314
- **Returns:** `Promise<{normal: bigint, fast: bigint}>` - Object containing bundler fee rates in wei
315
- - `normal`: Standard fee rate for normal UserOperation processing
316
- - `fast`: Higher fee rate for priority UserOperation processing
317
-
318
- **Example:**
319
- ```javascript
320
- const feeRates = await wallet.getFeeRates()
321
- console.log('Normal bundler fee:', feeRates.normal, 'wei')
322
- console.log('Fast bundler fee:', feeRates.fast, 'wei')
323
-
324
- // Use in UserOperation
325
- const result = await account.sendTransaction({
326
- to: '0x742C4265F5Ba4F8E0842e2b9EfE66302F7a13B6F',
327
- value: 1000000000000000000n, // 1 ETH
328
- maxFeePerGas: feeRates.fast,
329
- maxPriorityFeePerGas: feeRates.normal
330
- })
331
- ```
332
-
333
- ##### `dispose()`
334
- Disposes all ERC-4337 wallet accounts and clears sensitive data from memory.
335
-
336
- **Returns:** `void`
337
-
338
- **Example:**
339
- ```javascript
340
43
  wallet.dispose()
341
- // All smart accounts and private keys are now securely wiped from memory
342
44
  ```
343
45
 
344
- ### WalletAccountEvmErc4337
345
-
346
- Represents an individual ERC-4337 wallet account. Implements `IWalletAccount` from `@tetherto/wdk-wallet`.
46
+ ### Authenticated bundlers and paymasters
347
47
 
348
- #### Constructor
48
+ Some providers require an API key sent as an HTTP header. Pass `bundlerHeaders` and/or
49
+ `paymasterHeaders` to attach headers to every request to those services:
349
50
 
350
51
  ```javascript
351
- new WalletAccountEvmErc4337(seed, path, config)
352
- ```
353
-
354
- **Parameters:**
355
- - `seed` (string | Uint8Array): BIP-39 mnemonic seed phrase or seed bytes
356
- - `path` (string): BIP-44 derivation path (e.g., "0'/0/0")
357
- - `config` (object): Configuration object
358
- - `provider` (string | Eip1193Provider): RPC endpoint URL or EIP-1193 provider instance
359
- - `bundlerUrl` (string): URL of the ERC-4337 bundler service
360
- - `entryPointAddress` (string): Address of the EntryPoint contract
361
- - `factoryAddress` (string): Address of the account factory contract
362
- - `chainId` (number): Chain ID of the target network
363
- - `paymasterUrl` (string, optional): URL of the paymaster service
364
- - `transferMaxFee` (number | bigint, optional): Maximum fee amount for transfer operations (in wei)
365
-
366
- #### Methods
367
-
368
- | Method | Description | Returns |
369
- |--------|-------------|---------|
370
- | `getAddress()` | Returns the smart contract wallet address | `Promise<string>` |
371
- | `sign(message)` | Signs a message using the account's private key | `Promise<string>` |
372
- | `verify(message, signature)` | Verifies a message signature | `Promise<boolean>` |
373
- | `sendTransaction(tx)` | Sends a transaction via UserOperation | `Promise<{hash: string, fee: bigint}>` |
374
- | `quoteSendTransaction(tx)` | Estimates the fee for a UserOperation | `Promise<{fee: bigint}>` |
375
- | `transfer(options)` | Transfers ERC20 tokens via UserOperation | `Promise<{hash: string, fee: bigint}>` |
376
- | `quoteTransfer(options)` | Estimates the fee for an ERC20 transfer | `Promise<{fee: bigint}>` |
377
- | `getBalance()` | Returns the native token balance (in wei) | `Promise<bigint>` |
378
- | `getTokenBalance(tokenAddress)` | Returns the balance of a specific ERC20 token | `Promise<bigint>` |
379
- | `dispose()` | Disposes the wallet account, clearing private keys from memory | `void` |
380
-
381
- ##### `getAddress()`
382
- Returns the smart contract wallet address (not the EOA address).
383
-
384
- **Returns:** `Promise<string>` - The smart contract wallet address
385
-
386
- **Example:**
387
- ```javascript
388
- const smartAccountAddress = await account.getAddress()
389
- console.log('Smart account address:', smartAccountAddress) // 0x123... (contract address)
390
- ```
391
-
392
- ##### `sign(message)`
393
- Signs a message using the account's private key (EOA signing for the smart account).
394
-
395
- **Parameters:**
396
- - `message` (string): Message to sign
397
-
398
- **Returns:** `Promise<string>` - Signature as hex string
399
-
400
- **Example:**
401
- ```javascript
402
- const signature = await account.sign('Hello ERC-4337!')
403
- console.log('Signature:', signature)
404
- ```
405
-
406
- ##### `verify(message, signature)`
407
- Verifies a message signature using the account's public key.
408
-
409
- **Parameters:**
410
- - `message` (string): Original message
411
- - `signature` (string): Signature as hex string
412
-
413
- **Returns:** `Promise<boolean>` - True if signature is valid
414
-
415
- **Example:**
416
- ```javascript
417
- const isValid = await account.verify('Hello ERC-4337!', signature)
418
- console.log('Signature valid:', isValid)
419
- ```
420
-
421
- ##### `sendTransaction(tx)`
422
- Sends a transaction via UserOperation through the ERC-4337 bundler.
423
-
424
- **Parameters:**
425
- - `tx` (object): The transaction object
426
- - `to` (string): Recipient address
427
- - `value` (number | bigint): Amount in wei
428
- - `data` (string, optional): Transaction data in hex format
429
- - `gasLimit` (number | bigint, optional): Maximum gas units for the UserOperation
430
- - `maxFeePerGas` (number | bigint, optional): EIP-1559 max fee per gas in wei
431
- - `maxPriorityFeePerGas` (number | bigint, optional): EIP-1559 max priority fee per gas in wei
432
-
433
- **Returns:** `Promise<{hash: string, fee: bigint}>` - Object containing UserOperation hash and total fee (in wei)
434
-
435
- **Example:**
436
- ```javascript
437
- const result = await account.sendTransaction({
438
- to: '0x742C4265F5Ba4F8E0842e2b9EfE66302F7a13B6F',
439
- value: 1000000000000000000n, // 1 ETH in wei
440
- maxFeePerGas: 20000000000n, // 20 gwei
441
- maxPriorityFeePerGas: 2000000000n // 2 gwei
442
- })
443
- console.log('UserOperation hash:', result.hash)
444
- console.log('Total fee paid:', result.fee, 'wei')
445
- ```
446
-
447
- ##### `quoteSendTransaction(tx)`
448
- Estimates the fee for a UserOperation without submitting it to the bundler.
449
-
450
- **Parameters:**
451
- - `tx` (object): Same as sendTransaction parameters
452
- - `to` (string): Recipient address
453
- - `value` (number | bigint): Amount in wei
454
- - `data` (string, optional): Transaction data in hex format
455
- - `gasLimit` (number | bigint, optional): Maximum gas units
456
- - `maxFeePerGas` (number | bigint, optional): EIP-1559 max fee per gas in wei
457
- - `maxPriorityFeePerGas` (number | bigint, optional): EIP-1559 max priority fee per gas in wei
458
-
459
- **Returns:** `Promise<{fee: bigint}>` - Object containing estimated total fee (in wei)
460
-
461
- **Example:**
462
- ```javascript
463
- const quote = await account.quoteSendTransaction({
464
- to: '0x742C4265F5Ba4F8E0842e2b9EfE66302F7a13B6F',
465
- value: 1000000000000000000n // 1 ETH in wei
466
- })
467
- console.log('Estimated UserOperation fee:', quote.fee, 'wei')
468
- console.log('Estimated fee in ETH:', Number(quote.fee) / 1e18)
469
- ```
470
-
471
- ##### `transfer(options)`
472
- Transfers ERC20 tokens via UserOperation through the bundler.
473
-
474
- **Parameters:**
475
- - `options` (object): Transfer options
476
- - `to` (string): Recipient address
477
- - `tokenAddress` (string): ERC20 token contract address
478
- - `value` (number | bigint): Amount in token's smallest unit
479
- - `gasLimit` (number | bigint, optional): Maximum gas units
480
- - `maxFeePerGas` (number | bigint, optional): EIP-1559 max fee per gas in wei
481
- - `maxPriorityFeePerGas` (number | bigint, optional): EIP-1559 max priority fee per gas in wei
482
-
483
- **Returns:** `Promise<{hash: string, fee: bigint}>` - Object containing UserOperation hash and fee (in wei)
484
-
485
- **Example:**
486
- ```javascript
487
- const result = await account.transfer({
488
- to: '0x742C4265F5Ba4F8E0842e2b9EfE66302F7a13B6F',
489
- tokenAddress: '0xdAC17F958D2ee523a2206206994597C13D831ec7', // USDT
490
- value: 1000000n, // 1 USDT (6 decimals)
491
- maxFeePerGas: 20000000000n
492
- })
493
- console.log('UserOperation hash:', result.hash)
494
- console.log('Gas fee paid:', result.fee, 'wei')
495
- ```
496
-
497
- ##### `quoteTransfer(options)`
498
- Estimates the fee for an ERC20 token transfer UserOperation without submitting it.
499
-
500
- **Parameters:**
501
- - `options` (object): Same as transfer parameters
502
- - `to` (string): Recipient address
503
- - `tokenAddress` (string): ERC20 token contract address
504
- - `value` (number | bigint): Amount in token's smallest unit
505
- - `gasLimit` (number | bigint, optional): Maximum gas units
506
- - `maxFeePerGas` (number | bigint, optional): EIP-1559 max fee per gas in wei
507
- - `maxPriorityFeePerGas` (number | bigint, optional): EIP-1559 max priority fee per gas in wei
508
-
509
- **Returns:** `Promise<{fee: bigint}>` - Object containing estimated fee (in wei)
510
-
511
- **Example:**
512
- ```javascript
513
- const quote = await account.quoteTransfer({
514
- to: '0x742C4265F5Ba4F8E0842e2b9EfE66302F7a13B6F',
515
- tokenAddress: '0xdAC17F958D2ee523a2206206994597C13D831ec7', // USDT
516
- value: 1000000n // 1 USDT (6 decimals)
52
+ const wallet = new WalletManagerEvmErc4337(seedPhrase, {
53
+ chainId: 11155111,
54
+ provider: 'https://sepolia.drpc.org',
55
+ bundlerUrl: 'https://bundler.example.com/rpc',
56
+ bundlerHeaders: { Authorization: 'Bearer YOUR_KEY' },
57
+ safeModulesVersion: '0.3.0',
58
+ isSponsored: true,
59
+ paymasterUrl: 'https://paymaster.example.com/rpc',
60
+ paymasterHeaders: { Authorization: 'Bearer YOUR_KEY' },
517
61
  })
518
- console.log('Estimated transfer fee:', quote.fee, 'wei')
519
62
  ```
520
63
 
521
- ##### `getBalance()`
522
- Returns the smart contract wallet's native token balance (e.g., ETH, MATIC, etc.) in wei.
64
+ Both fields are optional. When omitted, requests are sent without extra headers, so providers
65
+ that authenticate via the URL (e.g. an `apikey` query parameter) keep working unchanged.
523
66
 
524
- **Returns:** `Promise<bigint>` - Balance in wei
525
-
526
- **Example:**
527
- ```javascript
528
- const balance = await account.getBalance()
529
- console.log('Smart account balance:', balance, 'wei')
530
- console.log('Balance in ETH:', Number(balance) / 1e18)
531
- ```
67
+ ## Key Capabilities
532
68
 
533
- ##### `getTokenBalance(tokenAddress)`
534
- Returns the smart contract wallet's balance of a specific ERC20 token.
535
-
536
- **Parameters:**
537
- - `tokenAddress` (string): The ERC20 token contract address
538
-
539
- **Returns:** `Promise<bigint>` - Token balance in token's smallest unit
540
-
541
- **Example:**
542
- ```javascript
543
- // Get USDT balance (6 decimals)
544
- const usdtBalance = await account.getTokenBalance('0xdAC17F958D2ee523a2206206994597C13D831ec7')
545
- console.log('Smart account USDT balance:', Number(usdtBalance) / 1e6)
546
- ```
547
-
548
- ##### `dispose()`
549
- Disposes the wallet account, securely erasing the private key from memory.
550
-
551
- **Returns:** `void`
552
-
553
- **Example:**
554
- ```javascript
555
- account.dispose()
556
- // Private key is now securely wiped from memory
557
- ```
558
-
559
- #### Properties
560
-
561
- | Property | Type | Description |
562
- |----------|------|-------------|
563
- | `index` | `number` | The derivation path's index of this account |
564
- | `path` | `string` | The full derivation path of this account |
565
- | `keyPair` | `object` | The account's key pair (⚠️ Contains sensitive data) |
566
-
567
- ⚠️ **Security Note**: The `keyPair` property contains sensitive cryptographic material. Never log, display, or expose the private key.
568
-
569
- ### WalletAccountReadOnlyEvmErc4337
570
-
571
- Represents a read-only ERC-4337 wallet account.
572
-
573
- #### Constructor
574
-
575
- ```javascript
576
- new WalletAccountReadOnlyEvmErc4337(address, config)
577
- ```
578
-
579
- **Parameters:**
580
- - `address` (string): The smart contract wallet address
581
- - `config` (object): Configuration object
582
- - `provider` (string | Eip1193Provider): RPC endpoint URL or EIP-1193 provider instance
583
- - `bundlerUrl` (string): URL of the ERC-4337 bundler service
584
- - `entryPointAddress` (string): Address of the EntryPoint contract
585
-
586
- #### Methods
587
-
588
- | Method | Description | Returns |
589
- |--------|-------------|---------|
590
- | `getBalance()` | Returns the native token balance (in wei) | `Promise<bigint>` |
591
- | `getTokenBalance(tokenAddress)` | Returns the balance of a specific ERC20 token | `Promise<bigint>` |
592
- | `quoteSendTransaction(tx)` | Estimates the fee for a UserOperation | `Promise<{fee: bigint}>` |
593
- | `quoteTransfer(options)` | Estimates the fee for an ERC20 transfer | `Promise<{fee: bigint}>` |
594
-
595
- ##### `getBalance()`
596
- Returns the smart contract wallet's native token balance (e.g., ETH, MATIC, etc.) in wei.
597
-
598
- **Returns:** `Promise<bigint>` - Balance in wei
599
-
600
- **Example:**
601
- ```javascript
602
- const balance = await readOnlyAccount.getBalance()
603
- console.log('Smart account balance:', balance, 'wei')
604
- console.log('Balance in ETH:', Number(balance) / 1e18)
605
- ```
606
-
607
- ##### `getTokenBalance(tokenAddress)`
608
- Returns the smart contract wallet's balance of a specific ERC20 token.
609
-
610
- **Parameters:**
611
- - `tokenAddress` (string): The ERC20 token contract address
612
-
613
- **Returns:** `Promise<bigint>` - Token balance in token's smallest unit
614
-
615
- **Example:**
616
- ```javascript
617
- // Get USDT balance (6 decimals) for the smart account
618
- const usdtBalance = await readOnlyAccount.getTokenBalance('0xdAC17F958D2ee523a2206206994597C13D831ec7')
619
- console.log('Smart account USDT balance:', Number(usdtBalance) / 1e6)
620
- ```
621
-
622
- ##### `quoteSendTransaction(tx)`
623
- Estimates the fee for a UserOperation without submitting it to the bundler.
69
+ - **ERC-4337 Account Abstraction**: Full implementation of the ERC-4337 standard
70
+ - **Multiple Gas Payment Modes**: Pay fees with native coins, ERC-20 tokens via paymaster, or sponsored transactions
71
+ - **UserOperation Management**: Create and send UserOperations through bundlers
72
+ - **Authenticated Bundlers & Paymasters**: Attach custom HTTP headers (e.g. `Authorization`) to bundler and paymaster requests
73
+ - **BIP-44 Derivation Paths**: Standard Ethereum derivation (m/44'/60')
74
+ - **Multi-Account Management**: Derive multiple smart accounts from a single seed phrase
75
+ - **ERC-20 Token Support**: Query balances and transfer tokens via UserOperations
76
+ - **Message Signing**: Sign and verify messages with the underlying EOA key
77
+ - **Per-Call Config Overrides**: Switch gas payment modes on a per-transaction basis
78
+ - **Parallel Nonce Lanes**: Send independent operations concurrently via ERC-4337 two-dimensional nonces (`parallel: true` or a reusable `nonceKey`)
79
+ - **Secure Memory Disposal**: Clear private keys from memory when done
624
80
 
625
- **Parameters:**
626
- - `tx` (object): The transaction object
627
- - `to` (string): Recipient address
628
- - `value` (number | bigint): Amount in wei
629
- - `data` (string, optional): Transaction data in hex format
630
- - `gasLimit` (number | bigint, optional): Maximum gas units
631
- - `maxFeePerGas` (number | bigint, optional): EIP-1559 max fee per gas in wei
632
- - `maxPriorityFeePerGas` (number | bigint, optional): EIP-1559 max priority fee per gas in wei
81
+ ## Concurrent / Parallel Sends (nonce lanes)
633
82
 
634
- **Returns:** `Promise<{fee: bigint}>` - Object containing estimated total UserOperation fee (in wei)
83
+ By default every send uses the account's key-0 nonce, so it is sequential — a second send fired before the first is mined would collide on the nonce. To send independent operations concurrently, put each in its own **nonce lane** (an ERC-4337 two-dimensional nonce: a 192-bit `key` with its own sequence). Ops in different keys have no ordering constraint and validate independently, so they can be submitted at the same time.
635
84
 
636
- **Example:**
637
85
  ```javascript
638
- const quote = await readOnlyAccount.quoteSendTransaction({
639
- to: '0x742C4265F5Ba4F8E0842e2b9EfE66302F7a13B6F',
640
- value: 1000000000000000000n // 1 ETH in wei
641
- })
642
- console.log('Estimated UserOperation fee:', quote.fee, 'wei')
643
- console.log('Estimated fee in ETH:', Number(quote.fee) / 1e18)
644
- ```
645
-
646
- ##### `quoteTransfer(options)`
647
- Estimates the fee for an ERC20 token transfer UserOperation without submitting it to the bundler.
648
-
649
- **Parameters:**
650
- - `options` (object): Transfer options
651
- - `to` (string): Recipient address
652
- - `tokenAddress` (string): ERC20 token contract address
653
- - `value` (number | bigint): Amount in token's smallest unit
654
- - `gasLimit` (number | bigint, optional): Maximum gas units
655
- - `maxFeePerGas` (number | bigint, optional): EIP-1559 max fee per gas in wei
656
- - `maxPriorityFeePerGas` (number | bigint, optional): EIP-1559 max priority fee per gas in wei
86
+ // parallel: true → each send gets a fresh random lane (sequence 0). Fire them together:
87
+ const [a, b] = await Promise.all([
88
+ account.sendTransaction({ to: '0x...', value: 0n }, { parallel: true }),
89
+ account.sendTransaction({ to: '0x...', value: 0n }, { parallel: true })
90
+ ])
657
91
 
658
- **Returns:** `Promise<{fee: bigint}>` - Object containing estimated UserOperation fee (in wei)
659
-
660
- **Example:**
661
- ```javascript
662
- const quote = await readOnlyAccount.quoteTransfer({
663
- to: '0x742C4265F5Ba4F8E0842e2b9EfE66302F7a13B6F',
664
- tokenAddress: '0xdAC17F958D2ee523a2206206994597C13D831ec7', // USDT
665
- value: 1000000n // 1 USDT (6 decimals)
666
- })
667
- console.log('Estimated transfer UserOperation fee:', quote.fee, 'wei')
668
- console.log('Estimated fee in ETH:', Number(quote.fee) / 1e18)
92
+ // nonceKey: a string is a reusable named lane (same label resumes the same lane across sessions);
93
+ // a bigint is used as the raw uint192 key. Same key = ordered; different keys = parallel.
94
+ await account.sendTransaction(tx, { nonceKey: 'payments' })
95
+ await account.sendTransaction(tx, { nonceKey: 1n })
669
96
  ```
670
97
 
671
- ## 🌐 Supported Networks
98
+ Both options can also be set at construction (`new WalletManagerEvmErc4337(seed, { ..., parallel: true })`) and overridden per call. Precedence: `nonceKey` > `parallel` > default (key 0).
672
99
 
673
- This package works with any EVM-compatible blockchain that supports ERC-4337, including:
100
+ **Notes:**
101
+ - **Deploy the account first.** A Safe smart account is deployed by its first UserOperation (which carries the init code). Concurrent sends from an **undeployed** account can't each carry the init code, so let one send land (deploying the account) before firing parallel lanes.
102
+ - **Requires a bundler that accepts parallel keys** (Pimlico and Candide both do). There is no SDK-side lane limit; respect your bundler's cap (e.g. Pimlico allows up to 100 parallel).
103
+ - **Per-sender mempool cap (≈4).** Per [ERC-7562](https://eips.ethereum.org/EIPS/eip-7562), a standard bundler mempool holds at most **4** in-flight UserOperations from a single sender at once (`SAME_SENDER_MEMPOOL_COUNT = 4`). Firing more than 4 lanes concurrently may be rejected until earlier ops mine. This is a mempool validation limit, separate from parallel-key support, and can be raised by the bundler operator if needed.
104
+ - `parallel: true` mints a **new** EntryPoint nonce slot per send (a one-time gas cost per lane; permanent state). For repeated parallel workloads, reuse a fixed set of lanes with `nonceKey` labels instead of a fresh key every time.
105
+ - A single lane is still **sequential**. Two concurrent sends sharing the same `nonceKey` collide on the sequence: the second is typically still **accepted by the bundler and returns a hash, yet can never mine** — its hash never resolves to a receipt and no error is thrown (a silent phantom hash). To run operations concurrently, give each its **own lane** (`parallel: true`, or distinct `nonceKey`s). If operations must share a lane, either **await each send's receipt before firing the next**, or **batch them into a single UserOperation** by passing an array to `sendTransaction([tx1, tx2, ...])` — batched calls execute atomically, in order, under one nonce.
674
106
 
675
- - **Ethereum Mainnet**
676
- - **Ethereum Testnets** (Sepolia, etc.)
677
- - **Layer 2 Networks** (Arbitrum, Optimism, etc.)
678
- - **Other EVM Chains** (Polygon, Avalanche C-Chain, etc.)
107
+ ## Compatibility
679
108
 
680
- ## 🔒 Security Considerations
109
+ - **Ethereum Mainnet** and testnets (Sepolia)
110
+ - **Layer 2 Networks**: Arbitrum, Optimism, Base
111
+ - **Other EVM Chains**: Polygon, Avalanche C-Chain, and any EVM-compatible chain with ERC-4337 support
681
112
 
682
- - **Seed Phrase Security**: Always store your seed phrase securely and never share it
683
- - **Private Key Management**: The package handles private keys internally with memory safety features
684
- - **Smart Contract Security**:
685
- - Verify EntryPoint contract addresses
686
- - Use audited account implementation contracts
687
- - Validate factory contract addresses
688
- - **Bundler Security**:
689
- - Use trusted bundler services
690
- - Validate UserOperation contents before signing
691
- - Monitor bundler responses for unexpected behavior
692
- - **Memory Cleanup**: Use the `dispose()` method to clear private keys from memory when done
693
- - **Fee Limits**: Set `transferMaxFee` to prevent excessive transaction fees
694
- - **Gas Estimation**: Always estimate gas before sending UserOperations
695
- - **Contract Interactions**:
696
- - Verify contract addresses and token decimals before transfers
697
- - Review UserOperation calldata before signing
698
- - **Network Validation**: Ensure correct EntryPoint and factory addresses for each network
113
+ ## Documentation
699
114
 
700
- ## 🛠️ Development
115
+ | Topic | Description | Link |
116
+ |-------|-------------|------|
117
+ | Overview | Module overview and feature summary | [Wallet EVM ERC-4337 Overview](https://docs.wdk.tether.io/sdk/wallet-modules/wallet-evm-erc-4337) |
118
+ | Usage | End-to-end integration walkthrough | [Wallet EVM ERC-4337 Usage](https://docs.wdk.tether.io/sdk/wallet-modules/wallet-evm-erc-4337/usage) |
119
+ | Configuration | Provider, bundler, paymaster, and network setup | [Wallet EVM ERC-4337 Configuration](https://docs.wdk.tether.io/sdk/wallet-modules/wallet-evm-erc-4337/configuration) |
120
+ | API Reference | Complete class and type reference | [Wallet EVM ERC-4337 API Reference](https://docs.wdk.tether.io/sdk/wallet-modules/wallet-evm-erc-4337/api-reference) |
701
121
 
702
- ### Building
122
+ ## Examples
703
123
 
704
- ```bash
705
- # Install dependencies
706
- npm install
124
+ | Example | Description |
125
+ |---------|-------------|
126
+ | [Create Wallet](https://github.com/tetherto/wdk-examples/blob/main/wallet-evm-erc-4337/create-wallet.ts) | Initialize ERC-4337 wallets with paymaster token and native coins modes |
127
+ | [Manage Accounts](https://github.com/tetherto/wdk-examples/blob/main/wallet-evm-erc-4337/manage-accounts.ts) | Work with multiple smart accounts and custom derivation paths |
128
+ | [Check Balances](https://github.com/tetherto/wdk-examples/blob/main/wallet-evm-erc-4337/check-balances.ts) | Query native token and ERC-20 balances for smart accounts |
129
+ | [Read-Only Account](https://github.com/tetherto/wdk-examples/blob/main/wallet-evm-erc-4337/read-only-account.ts) | Monitor smart account balances and estimate fees without a private key |
130
+ | [Send Transaction](https://github.com/tetherto/wdk-examples/blob/main/wallet-evm-erc-4337/send-transaction.ts) | Send transactions via UserOperations through the bundler |
131
+ | [Token Transfer](https://github.com/tetherto/wdk-examples/blob/main/wallet-evm-erc-4337/token-transfer.ts) | Transfer ERC-20 tokens via UserOperations with gas mode overrides |
132
+ | [Sign & Verify Message](https://github.com/tetherto/wdk-examples/blob/main/wallet-evm-erc-4337/sign-verify-message.ts) | Sign messages and verify signatures with ERC-4337 accounts |
133
+ | [Fee Management](https://github.com/tetherto/wdk-examples/blob/main/wallet-evm-erc-4337/fee-management.ts) | Retrieve current bundler fee rates |
134
+ | [Memory Management](https://github.com/tetherto/wdk-examples/blob/main/wallet-evm-erc-4337/memory-management.ts) | Securely dispose smart wallets and clear private keys from memory |
707
135
 
708
- # Build TypeScript definitions
709
- npm run build:types
136
+ > For detailed walkthroughs, see the [Usage Guide](https://docs.wdk.tether.io/sdk/wallet-modules/wallet-evm-erc-4337/usage).
137
+ > See all runnable examples in the [wdk-examples](https://github.com/tetherto/wdk-examples) repository.
710
138
 
711
- # Lint code
712
- npm run lint
139
+ ## Community
713
140
 
714
- # Fix linting issues
715
- npm run lint:fix
716
- ```
141
+ Join the [WDK Discord](https://discord.gg/arYXDhHB2w) to connect with other developers.
717
142
 
718
- ### Testing
143
+ ## Support
719
144
 
720
- ```bash
721
- # Run tests
722
- npm test
145
+ For support, please [open an issue](https://github.com/tetherto/wdk-wallet-evm-erc-4337/issues) on GitHub or reach out via [email](mailto:wallet-info@tether.io).
723
146
 
724
- # Run tests with coverage
725
- npm run test:coverage
726
- ```
727
-
728
- ## 📜 License
729
-
730
- This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.
731
-
732
- ## 🤝 Contributing
147
+ ## Contributing
733
148
 
734
149
  Contributions are welcome! Please feel free to submit a Pull Request.
735
150
 
736
- ## 🆘 Support
737
-
738
- For support, please open an issue on the GitHub repository.
151
+ ## License
739
152
 
740
- ---
153
+ This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.