@tetherto/wdk-wallet-evm-erc-4337 1.0.0-beta.1

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 ADDED
@@ -0,0 +1,740 @@
1
+ # @tetherto/wdk-wallet-evm-erc-4337
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.
10
+
11
+ For detailed documentation about the complete WDK ecosystem, visit [docs.wallet.tether.io](https://docs.wallet.tether.io).
12
+
13
+ ## 🌟 Features
14
+
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
20
+
21
+ ## ⬇️ Installation
22
+
23
+ To install the `@tetherto/wdk-wallet-evm-erc-4337` package, follow these instructions:
24
+
25
+ You can install it using npm:
26
+
27
+ ```bash
28
+ npm install @tetherto/wdk-wallet-evm-erc-4337
29
+ ```
30
+
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
68
+
69
+ ```javascript
70
+ import WalletManagerEvmErc4337 from '@tetherto/wdk-wallet-evm-erc-4337'
71
+
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) |
237
+
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
+ 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
269
+ })
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
+
289
+ **Example:**
290
+ ```javascript
291
+ const account = await wallet.getAccount(0)
292
+ const address = await account.getAddress()
293
+ 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
+
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
+ wallet.dispose()
341
+ // All smart accounts and private keys are now securely wiped from memory
342
+ ```
343
+
344
+ ### WalletAccountEvmErc4337
345
+
346
+ Represents an individual ERC-4337 wallet account. Implements `IWalletAccount` from `@tetherto/wdk-wallet`.
347
+
348
+ #### Constructor
349
+
350
+ ```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)
517
+ })
518
+ console.log('Estimated transfer fee:', quote.fee, 'wei')
519
+ ```
520
+
521
+ ##### `getBalance()`
522
+ Returns the smart contract wallet's native token balance (e.g., ETH, MATIC, etc.) in wei.
523
+
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
+ ```
532
+
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.
624
+
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
633
+
634
+ **Returns:** `Promise<{fee: bigint}>` - Object containing estimated total UserOperation fee (in wei)
635
+
636
+ **Example:**
637
+ ```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
657
+
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)
669
+ ```
670
+
671
+ ## 🌐 Supported Networks
672
+
673
+ This package works with any EVM-compatible blockchain that supports ERC-4337, including:
674
+
675
+ - **Ethereum Mainnet**
676
+ - **Ethereum Testnets** (Sepolia, etc.)
677
+ - **Layer 2 Networks** (Arbitrum, Optimism, etc.)
678
+ - **Other EVM Chains** (Polygon, Avalanche C-Chain, etc.)
679
+
680
+ ## 🔒 Security Considerations
681
+
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
699
+
700
+ ## 🛠️ Development
701
+
702
+ ### Building
703
+
704
+ ```bash
705
+ # Install dependencies
706
+ npm install
707
+
708
+ # Build TypeScript definitions
709
+ npm run build:types
710
+
711
+ # Lint code
712
+ npm run lint
713
+
714
+ # Fix linting issues
715
+ npm run lint:fix
716
+ ```
717
+
718
+ ### Testing
719
+
720
+ ```bash
721
+ # Run tests
722
+ npm test
723
+
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
733
+
734
+ Contributions are welcome! Please feel free to submit a Pull Request.
735
+
736
+ ## 🆘 Support
737
+
738
+ For support, please open an issue on the GitHub repository.
739
+
740
+ ---