@tetherto/wdk-wallet-evm-erc-4337 1.0.0-beta.6 → 1.0.0-beta.7
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 +57 -913
- package/hardhat.config.cjs +0 -1
- package/index.js +8 -1
- package/package.json +11 -7
- package/src/wallet-account-evm-erc-4337.js +180 -61
- package/src/wallet-account-read-only-evm-erc-4337.js +337 -138
- package/src/wallet-manager-evm-erc-4337.js +27 -8
- package/types/index.d.ts +8 -1
- package/types/src/wallet-account-evm-erc-4337.d.ts +37 -12
- package/types/src/wallet-account-read-only-evm-erc-4337.d.ts +153 -44
- package/types/src/wallet-manager-evm-erc-4337.d.ts +2 -9
package/README.md
CHANGED
|
@@ -1,960 +1,104 @@
|
|
|
1
1
|
# @tetherto/wdk-wallet-evm-erc-4337
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@tetherto/wdk-wallet-evm-erc-4337)
|
|
4
|
+
[](https://www.npmjs.com/package/@tetherto/wdk-wallet-evm-erc-4337)
|
|
5
|
+
[](https://github.com/tetherto/wdk-wallet-evm-erc-4337/blob/main/LICENSE)
|
|
6
|
+
[](https://docs.wdk.tether.io/sdk/wallet-modules/wallet-evm-erc-4337)
|
|
7
|
+
|
|
3
8
|
**Note**: This package is currently in beta. Please test thoroughly in development environments before using in production.
|
|
4
9
|
|
|
5
10
|
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
11
|
|
|
7
|
-
##
|
|
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
|
+
## About WDK
|
|
12
13
|
|
|
13
|
-
|
|
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
|
|
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.
|
|
20
15
|
|
|
21
|
-
|
|
16
|
+
For detailed documentation about the complete WDK ecosystem, visit [docs.wdk.tether.io](https://docs.wdk.tether.io).
|
|
22
17
|
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
##
|
|
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 (paymaster token mode)
|
|
47
|
-
const wallet = new WalletManagerEvmErc4337(seedPhrase, {
|
|
48
|
-
// Common parameters (required for all modes)
|
|
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
|
-
safeModulesVersion: '0.3.0',
|
|
54
|
-
|
|
55
|
-
// Paymaster token mode parameters
|
|
56
|
-
paymasterUrl: 'https://api.paymaster.com',
|
|
57
|
-
paymasterAddress: '0x8b1f6cb5d062aa2ce8d581942bbb960420d875ba',
|
|
58
|
-
paymasterToken: { address: '0xdAC17F958D2ee523a2206206994597C13D831ec7' }, // USDT
|
|
59
|
-
transferMaxFee: 100000000000000 // Optional: Maximum fee in wei
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
// Or use native coins mode (no paymaster needed)
|
|
63
|
-
const nativeWallet = new WalletManagerEvmErc4337(seedPhrase, {
|
|
64
|
-
chainId: 1,
|
|
65
|
-
provider: 'https://eth-mainnet.g.alchemy.com/v2/your-api-key',
|
|
66
|
-
bundlerUrl: 'https://api.stackup.sh/v1/bundler/your-api-key',
|
|
67
|
-
entryPointAddress: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789',
|
|
68
|
-
safeModulesVersion: '0.3.0',
|
|
69
|
-
useNativeCoins: true
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
// Get a full access account
|
|
73
|
-
const account = await wallet.getAccount(0)
|
|
74
|
-
|
|
75
|
-
// Convert to a read-only account
|
|
76
|
-
const readOnlyAccount = await account.toReadOnlyAccount()
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### Managing Multiple Accounts
|
|
80
|
-
|
|
81
|
-
```javascript
|
|
82
|
-
import WalletManagerEvmErc4337 from '@tetherto/wdk-wallet-evm-erc-4337'
|
|
83
|
-
|
|
84
|
-
// Assume wallet is already created
|
|
85
|
-
// Get the first account (index 0)
|
|
86
|
-
const account = await wallet.getAccount(0)
|
|
87
|
-
const address = await account.getAddress()
|
|
88
|
-
console.log('Account 0 address:', address)
|
|
89
|
-
|
|
90
|
-
// Get the second account (index 1)
|
|
91
|
-
const account1 = await wallet.getAccount(1)
|
|
92
|
-
const address1 = await account1.getAddress()
|
|
93
|
-
console.log('Account 1 address:', address1)
|
|
94
|
-
|
|
95
|
-
// Get account by custom derivation path
|
|
96
|
-
// Full path will be m/44'/60'/0'/0/5
|
|
97
|
-
const customAccount = await wallet.getAccountByPath("0'/0/5")
|
|
98
|
-
const customAddress = await customAccount.getAddress()
|
|
99
|
-
console.log('Custom account address:', customAddress)
|
|
100
|
-
|
|
101
|
-
// Note: All addresses are checksummed Ethereum addresses (0x...)
|
|
102
|
-
// All accounts inherit the provider configuration from the wallet manager
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
### Checking Balances
|
|
106
|
-
|
|
107
|
-
#### Owned Account
|
|
108
|
-
|
|
109
|
-
For accounts where you have the seed phrase and full access:
|
|
24
|
+
## Quick Start
|
|
110
25
|
|
|
111
26
|
```javascript
|
|
112
27
|
import WalletManagerEvmErc4337 from '@tetherto/wdk-wallet-evm-erc-4337'
|
|
113
28
|
|
|
114
|
-
|
|
115
|
-
// Get native token balance (in wei)
|
|
116
|
-
const balance = await account.getBalance()
|
|
117
|
-
console.log('Native balance:', balance, 'wei') // 1 ETH = 1000000000000000000 wei
|
|
118
|
-
|
|
119
|
-
// Get ERC20 token balance
|
|
120
|
-
const tokenContract = '0x...'; // ERC20 contract address
|
|
121
|
-
|
|
122
|
-
const tokenBalance = await account.getTokenBalance(tokenContract);
|
|
123
|
-
console.log('Token balance:', tokenBalance);
|
|
124
|
-
|
|
125
|
-
// Note: Provider is required for balance checks
|
|
126
|
-
// Make sure wallet was created with a provider configuration
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
#### Read-Only Account
|
|
130
|
-
|
|
131
|
-
For addresses where you don't have the seed phrase:
|
|
132
|
-
|
|
133
|
-
```javascript
|
|
134
|
-
import { WalletAccountReadOnlyEvmErc4337 } from '@tetherto/wdk-wallet-evm-erc-4337'
|
|
135
|
-
|
|
136
|
-
// Create a read-only account (native coins mode — no paymaster needed for quoting)
|
|
137
|
-
const readOnlyAccount = new WalletAccountReadOnlyEvmErc4337('0x636e9c21f27d9401ac180666bf8DC0D3FcEb0D24', { // Smart contract wallet address
|
|
138
|
-
provider: 'https://eth-mainnet.g.alchemy.com/v2/your-api-key',
|
|
139
|
-
bundlerUrl: 'https://api.stackup.sh/v1/bundler/your-api-key',
|
|
140
|
-
entryPointAddress: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789',
|
|
141
|
-
safeModulesVersion: '0.3.0',
|
|
142
|
-
useNativeCoins: true
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
// Check native token balance
|
|
146
|
-
const balance = await readOnlyAccount.getBalance()
|
|
147
|
-
console.log('Native balance:', balance, 'wei')
|
|
148
|
-
|
|
149
|
-
// Check ERC20 token balance using contract
|
|
150
|
-
const tokenBalance = await readOnlyAccount.getTokenBalance('0xdAC17F958D2ee523a2206206994597C13D831ec7') // USDT contract address
|
|
151
|
-
console.log('Token balance:', tokenBalance)
|
|
152
|
-
|
|
153
|
-
// Note: ERC20 balance checks use the standard balanceOf(address) function
|
|
154
|
-
// Make sure the contract address is correct and implements the ERC20 standard
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
### Sending Transactions
|
|
158
|
-
|
|
159
|
-
Send transactions using UserOperations through the bundler service. All transactions are handled via the EntryPoint contract.
|
|
29
|
+
const seedPhrase = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about'
|
|
160
30
|
|
|
161
|
-
```javascript
|
|
162
|
-
// Send native tokens via UserOperation
|
|
163
|
-
const result = await account.sendTransaction({
|
|
164
|
-
to: '0x636e9c21f27d9401ac180666bf8DC0D3FcEb0D24', // Recipient address
|
|
165
|
-
value: 1000000000000000000n, // 1 ETH in wei
|
|
166
|
-
data: '0x', // Optional: transaction data
|
|
167
|
-
})
|
|
168
|
-
console.log('UserOperation hash:', result.hash)
|
|
169
|
-
console.log('Transaction fee:', result.fee, 'wei')
|
|
170
|
-
|
|
171
|
-
// Get transaction fee estimate
|
|
172
|
-
const quote = await account.quoteSendTransaction({
|
|
173
|
-
to: '0x636e9c21f27d9401ac180666bf8DC0D3FcEb0D24',
|
|
174
|
-
value: 1000000000000000000n
|
|
175
|
-
});
|
|
176
|
-
console.log('Estimated fee:', quote.fee, 'wei');
|
|
177
|
-
|
|
178
|
-
// Note: Fees are calculated by the bundler and may include paymaster costs
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
### Token Transfers
|
|
182
|
-
|
|
183
|
-
Transfer ERC20 tokens using UserOperations. Uses standard ERC20 `transfer` function.
|
|
184
|
-
|
|
185
|
-
```javascript
|
|
186
|
-
// Transfer ERC20 tokens via UserOperation
|
|
187
|
-
const transferResult = await account.transfer({
|
|
188
|
-
token: '0xdAC17F958D2ee523a2206206994597C13D831ec7', // USDT contract address
|
|
189
|
-
recipient: '0x636e9c21f27d9401ac180666bf8DC0D3FcEb0D24', // Recipient's address
|
|
190
|
-
amount: 1000000n // Amount in token's base units (1 USDT = 1000000 for 6 decimals)
|
|
191
|
-
})
|
|
192
|
-
console.log('UserOperation hash:', transferResult.hash)
|
|
193
|
-
console.log('Transfer fee:', transferResult.fee, 'wei')
|
|
194
|
-
|
|
195
|
-
// Quote token transfer fee
|
|
196
|
-
const transferQuote = await account.quoteTransfer({
|
|
197
|
-
token: '0xdAC17F958D2ee523a2206206994597C13D831ec7', // USDT contract address
|
|
198
|
-
recipient: '0x636e9c21f27d9401ac180666bf8DC0D3FcEb0D24', // Recipient's address
|
|
199
|
-
amount: 1000000n // Amount in token's base units
|
|
200
|
-
})
|
|
201
|
-
console.log('Transfer fee estimate:', transferQuote.fee, 'wei')
|
|
202
|
-
|
|
203
|
-
// Transfer using native coins for gas (override constructor config)
|
|
204
|
-
const nativeTransfer = await account.transfer({
|
|
205
|
-
token: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
|
|
206
|
-
recipient: '0x636e9c21f27d9401ac180666bf8DC0D3FcEb0D24',
|
|
207
|
-
amount: 1000000n
|
|
208
|
-
}, { useNativeCoins: true })
|
|
209
|
-
console.log('Native gas transfer hash:', nativeTransfer.hash)
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
### Message Signing and Verification
|
|
213
|
-
|
|
214
|
-
Sign and verify messages using `WalletAccountEvmErc4337`.
|
|
215
|
-
|
|
216
|
-
```javascript
|
|
217
|
-
// Sign a message
|
|
218
|
-
const message = 'Hello, Account Abstraction!'
|
|
219
|
-
const signature = await account.sign(message)
|
|
220
|
-
console.log('Signature:', signature)
|
|
221
|
-
|
|
222
|
-
// Verify a signature
|
|
223
|
-
const isValid = await account.verify(message, signature)
|
|
224
|
-
console.log('Signature valid:', isValid)
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
### Fee Management
|
|
228
|
-
|
|
229
|
-
Retrieve current fee rates using `WalletManagerEvmErc4337`. Uses bundler service for fee estimation.
|
|
230
|
-
|
|
231
|
-
```javascript
|
|
232
|
-
// Get current bundler fee rates
|
|
233
|
-
const feeRates = await wallet.getFeeRates();
|
|
234
|
-
console.log('Normal fee rate:', feeRates.normal, 'wei'); // Base bundler fee
|
|
235
|
-
console.log('Fast fee rate:', feeRates.fast, 'wei'); // Priority bundler fee
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
### Memory Management
|
|
239
|
-
|
|
240
|
-
Clear sensitive data from memory using `dispose` methods in `WalletAccountEvmErc4337` and `WalletManagerEvmErc4337`.
|
|
241
|
-
|
|
242
|
-
```javascript
|
|
243
|
-
// Dispose wallet accounts to clear private keys from memory
|
|
244
|
-
account.dispose()
|
|
245
|
-
|
|
246
|
-
// Dispose entire wallet manager
|
|
247
|
-
wallet.dispose()
|
|
248
|
-
```
|
|
249
|
-
|
|
250
|
-
## 📚 API Reference
|
|
251
|
-
|
|
252
|
-
### Table of Contents
|
|
253
|
-
|
|
254
|
-
| Class | Description | Methods |
|
|
255
|
-
|-------|-------------|---------|
|
|
256
|
-
| [WalletManagerEvmErc4337](#walletmanagerevmerc4337) | Main class for managing ERC-4337 wallets. Extends `WalletManager` from `@tetherto/wdk-wallet`. | [Constructor](#constructor), [Methods](#methods) |
|
|
257
|
-
| [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) |
|
|
258
|
-
| [WalletAccountReadOnlyEvmErc4337](#walletaccountreadonlyevmerc4337) | Read-only ERC-4337 wallet account. Extends `WalletAccountReadOnly` from `@tetherto/wdk-wallet`. | [Constructor](#constructor-2), [Methods](#methods-2) |
|
|
259
|
-
|
|
260
|
-
### WalletManagerEvmErc4337
|
|
261
|
-
|
|
262
|
-
The main class for managing ERC-4337 compliant wallets.
|
|
263
|
-
Extends `WalletManager` from `@tetherto/wdk-wallet`.
|
|
264
|
-
|
|
265
|
-
#### Constructor
|
|
266
|
-
|
|
267
|
-
```javascript
|
|
268
|
-
new WalletManagerEvmErc4337(seed, config)
|
|
269
|
-
```
|
|
270
|
-
|
|
271
|
-
**Parameters:**
|
|
272
|
-
- `seed` (string | Uint8Array): BIP-39 mnemonic seed phrase or seed bytes
|
|
273
|
-
- `config` (object): Configuration object. The configuration is a union of common fields and one of three gas payment modes.
|
|
274
|
-
|
|
275
|
-
**Common fields (required for all modes):**
|
|
276
|
-
- `chainId` (number): Chain ID of the target network
|
|
277
|
-
- `provider` (string | Eip1193Provider): RPC endpoint URL or EIP-1193 provider instance
|
|
278
|
-
- `bundlerUrl` (string): URL of the ERC-4337 bundler service
|
|
279
|
-
- `entryPointAddress` (string): Address of the EntryPoint contract
|
|
280
|
-
- `safeModulesVersion` (string): The safe modules version
|
|
281
|
-
|
|
282
|
-
**Paymaster token mode** (pay gas fees with an ERC-20 token via a paymaster):
|
|
283
|
-
- `paymasterUrl` (string): URL of the paymaster service
|
|
284
|
-
- `paymasterAddress` (string): Address of the paymaster smart contract
|
|
285
|
-
- `paymasterToken` (object): Paymaster token configuration
|
|
286
|
-
- `address` (string): Token contract address
|
|
287
|
-
- `transferMaxFee` (number | bigint, optional): Maximum fee amount for transfer operations
|
|
288
|
-
|
|
289
|
-
**Sponsorship mode** (gas fees are sponsored by a paymaster):
|
|
290
|
-
- `isSponsored` (true): Enables transaction sponsorship
|
|
291
|
-
- `paymasterUrl` (string): URL of the paymaster service
|
|
292
|
-
- `sponsorshipPolicyId` (string, optional): Sponsorship policy ID
|
|
293
|
-
|
|
294
|
-
**Native coins mode** (pay gas fees with native coins, e.g. ETH):
|
|
295
|
-
- `useNativeCoins` (true): Enables native coin gas payment
|
|
296
|
-
- `transferMaxFee` (number | bigint, optional): Maximum fee amount for transfer operations
|
|
297
|
-
|
|
298
|
-
**Example:**
|
|
299
|
-
```javascript
|
|
300
|
-
// Paymaster token mode
|
|
301
31
|
const wallet = new WalletManagerEvmErc4337(seedPhrase, {
|
|
302
|
-
chainId:
|
|
303
|
-
provider: 'https://
|
|
304
|
-
bundlerUrl: 'https://api.
|
|
305
|
-
entryPointAddress: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789',
|
|
32
|
+
chainId: 11155111, // Sepolia
|
|
33
|
+
provider: 'https://sepolia.drpc.org',
|
|
34
|
+
bundlerUrl: 'https://api.pimlico.io/v2/sepolia/rpc?apikey=YOUR_KEY',
|
|
306
35
|
safeModulesVersion: '0.3.0',
|
|
307
|
-
|
|
308
|
-
paymasterAddress: '0x8b1f6cb5d062aa2ce8d581942bbb960420d875ba',
|
|
309
|
-
paymasterToken: { address: '0xdAC17F958D2ee523a2206206994597C13D831ec7' },
|
|
310
|
-
transferMaxFee: 100000000000000n
|
|
36
|
+
useNativeCoins: true,
|
|
311
37
|
})
|
|
312
|
-
```
|
|
313
|
-
|
|
314
|
-
#### Methods
|
|
315
|
-
|
|
316
|
-
| Method | Description | Returns |
|
|
317
|
-
|--------|-------------|---------|
|
|
318
|
-
| `getAccount(index)` | Returns a wallet account at the specified index | `Promise<WalletAccountEvmErc4337>` |
|
|
319
|
-
| `getAccountByPath(path)` | Returns a wallet account at the specified BIP-44 derivation path | `Promise<WalletAccountEvmErc4337>` |
|
|
320
|
-
| `getFeeRates()` | Returns current bundler fee rates for UserOperations | `Promise<{normal: bigint, fast: bigint}>` |
|
|
321
|
-
| `dispose()` | Disposes all wallet accounts, clearing private keys from memory | `void` |
|
|
322
|
-
|
|
323
|
-
##### `getAccount(index)`
|
|
324
|
-
Returns an ERC-4337 wallet account at the specified index using BIP-44 derivation.
|
|
325
|
-
|
|
326
|
-
**Parameters:**
|
|
327
|
-
- `index` (number, optional): The index of the account to get (default: 0)
|
|
328
|
-
|
|
329
|
-
**Returns:** `Promise<WalletAccountEvmErc4337>` - The ERC-4337 wallet account
|
|
330
38
|
|
|
331
|
-
**Example:**
|
|
332
|
-
```javascript
|
|
333
39
|
const account = await wallet.getAccount(0)
|
|
334
40
|
const address = await account.getAddress()
|
|
335
41
|
console.log('Smart account address:', address)
|
|
336
|
-
```
|
|
337
|
-
|
|
338
|
-
##### `getAccountByPath(path)`
|
|
339
|
-
Returns an ERC-4337 wallet account at the specified BIP-44 derivation path.
|
|
340
|
-
|
|
341
|
-
**Parameters:**
|
|
342
|
-
- `path` (string): The derivation path (e.g., "0'/0/0", "1'/0/5")
|
|
343
|
-
|
|
344
|
-
**Returns:** `Promise<WalletAccountEvmErc4337>` - The ERC-4337 wallet account
|
|
345
|
-
|
|
346
|
-
**Example:**
|
|
347
|
-
```javascript
|
|
348
|
-
const account = await wallet.getAccountByPath("0'/0/1")
|
|
349
|
-
const address = await account.getAddress()
|
|
350
|
-
console.log('Smart account address:', address)
|
|
351
|
-
```
|
|
352
|
-
|
|
353
|
-
##### `getFeeRates()`
|
|
354
|
-
Returns current bundler fee rates for ERC-4337 UserOperations.
|
|
355
|
-
|
|
356
|
-
**Returns:** `Promise<{normal: bigint, fast: bigint}>` - Object containing bundler fee rates in wei
|
|
357
|
-
- `normal`: Standard fee rate for normal UserOperation processing
|
|
358
|
-
- `fast`: Higher fee rate for priority UserOperation processing
|
|
359
|
-
|
|
360
|
-
**Example:**
|
|
361
|
-
```javascript
|
|
362
|
-
const feeRates = await wallet.getFeeRates()
|
|
363
|
-
console.log('Normal bundler fee:', feeRates.normal, 'wei')
|
|
364
|
-
console.log('Fast bundler fee:', feeRates.fast, 'wei')
|
|
365
|
-
|
|
366
|
-
// Use in UserOperation
|
|
367
|
-
const result = await account.sendTransaction({
|
|
368
|
-
to: '0x742C4265F5Ba4F8E0842e2b9EfE66302F7a13B6F',
|
|
369
|
-
value: 1000000000000000000n, // 1 ETH
|
|
370
|
-
maxFeePerGas: feeRates.fast,
|
|
371
|
-
maxPriorityFeePerGas: feeRates.normal
|
|
372
|
-
})
|
|
373
|
-
```
|
|
374
|
-
|
|
375
|
-
##### `dispose()`
|
|
376
|
-
Disposes all ERC-4337 wallet accounts and clears sensitive data from memory.
|
|
377
42
|
|
|
378
|
-
**Returns:** `void`
|
|
379
|
-
|
|
380
|
-
**Example:**
|
|
381
|
-
```javascript
|
|
382
43
|
wallet.dispose()
|
|
383
|
-
// All smart accounts and private keys are now securely wiped from memory
|
|
384
|
-
```
|
|
385
|
-
|
|
386
|
-
### WalletAccountEvmErc4337
|
|
387
|
-
|
|
388
|
-
Represents an individual ERC-4337 wallet account. Implements `IWalletAccount` from `@tetherto/wdk-wallet`.
|
|
389
|
-
|
|
390
|
-
#### Constructor
|
|
391
|
-
|
|
392
|
-
```javascript
|
|
393
|
-
new WalletAccountEvmErc4337(seed, path, config)
|
|
394
|
-
```
|
|
395
|
-
|
|
396
|
-
**Parameters:**
|
|
397
|
-
- `seed` (string | Uint8Array): BIP-39 mnemonic seed phrase or seed bytes
|
|
398
|
-
- `path` (string): BIP-44 derivation path (e.g., "0'/0/0")
|
|
399
|
-
- `config` (object): Configuration object. Same configuration union as `WalletManagerEvmErc4337` — see [constructor parameters](#constructor) for the full description of common fields and the three gas payment modes (paymaster token, sponsorship, native coins).
|
|
400
|
-
|
|
401
|
-
#### Methods
|
|
402
|
-
|
|
403
|
-
| Method | Description | Returns |
|
|
404
|
-
|--------|-------------|---------|
|
|
405
|
-
| `getAddress()` | Returns the smart contract wallet address | `Promise<string>` |
|
|
406
|
-
| `sign(message)` | Signs a message using the account's private key | `Promise<string>` |
|
|
407
|
-
| `signTypedData(typedData)` | Signs typed data according to EIP-712 | `Promise<string>` |
|
|
408
|
-
| `verify(message, signature)` | Verifies a message signature | `Promise<boolean>` |
|
|
409
|
-
| `verifyTypedData(typedData, signature)` | Verifies a typed data signature | `Promise<boolean>` |
|
|
410
|
-
| `sendTransaction(tx, config)` | Sends a transaction via UserOperation | `Promise<{hash: string, fee: bigint}>` |
|
|
411
|
-
| `quoteSendTransaction(tx, config)` | Estimates the fee for a UserOperation | `Promise<{fee: bigint}>` |
|
|
412
|
-
| `transfer(options, config)` | Transfers ERC20 tokens via UserOperation | `Promise<{hash: string, fee: bigint}>` |
|
|
413
|
-
| `quoteTransfer(options, config)` | Estimates the fee for an ERC20 transfer | `Promise<{fee: bigint}>` |
|
|
414
|
-
| `getBalance()` | Returns the native token balance (in wei) | `Promise<bigint>` |
|
|
415
|
-
| `getTokenBalance(tokenAddress)` | Returns the balance of a specific ERC20 token | `Promise<bigint>` |
|
|
416
|
-
| `dispose()` | Disposes the wallet account, clearing private keys from memory | `void` |
|
|
417
|
-
|
|
418
|
-
##### `getAddress()`
|
|
419
|
-
Returns the smart contract wallet address (not the EOA address).
|
|
420
|
-
|
|
421
|
-
**Returns:** `Promise<string>` - The smart contract wallet address
|
|
422
|
-
|
|
423
|
-
**Example:**
|
|
424
|
-
```javascript
|
|
425
|
-
const smartAccountAddress = await account.getAddress()
|
|
426
|
-
console.log('Smart account address:', smartAccountAddress) // 0x123... (contract address)
|
|
427
|
-
```
|
|
428
|
-
|
|
429
|
-
##### `sign(message)`
|
|
430
|
-
Signs a message using the account's private key (EOA signing for the smart account).
|
|
431
|
-
|
|
432
|
-
**Parameters:**
|
|
433
|
-
- `message` (string): Message to sign
|
|
434
|
-
|
|
435
|
-
**Returns:** `Promise<string>` - Signature as hex string
|
|
436
|
-
|
|
437
|
-
**Example:**
|
|
438
|
-
```javascript
|
|
439
|
-
const signature = await account.sign('Hello ERC-4337!')
|
|
440
|
-
console.log('Signature:', signature)
|
|
441
|
-
```
|
|
442
|
-
|
|
443
|
-
##### `signTypedData(typedData)`
|
|
444
|
-
Signs typed data according to EIP-712.
|
|
445
|
-
|
|
446
|
-
**Parameters:**
|
|
447
|
-
- `typedData` (object):
|
|
448
|
-
- `domain` (object): The EIP-712 domain separator
|
|
449
|
-
- `types` (object): The type definitions
|
|
450
|
-
- `message` (object): The structured message to sign
|
|
451
|
-
|
|
452
|
-
**Returns:** `Promise<string>` - The typed data signature
|
|
453
|
-
|
|
454
|
-
**Example:**
|
|
455
|
-
```javascript
|
|
456
|
-
const signature = await account.signTypedData({
|
|
457
|
-
domain: {
|
|
458
|
-
name: 'MyDApp',
|
|
459
|
-
version: '1',
|
|
460
|
-
chainId: 1,
|
|
461
|
-
verifyingContract: '0x...'
|
|
462
|
-
},
|
|
463
|
-
types: {
|
|
464
|
-
Transfer: [
|
|
465
|
-
{ name: 'to', type: 'address' },
|
|
466
|
-
{ name: 'amount', type: 'uint256' }
|
|
467
|
-
]
|
|
468
|
-
},
|
|
469
|
-
message: {
|
|
470
|
-
to: '0x1234567890abcdef1234567890abcdef12345678',
|
|
471
|
-
amount: '1000000'
|
|
472
|
-
}
|
|
473
|
-
})
|
|
474
|
-
console.log('Typed data signature:', signature)
|
|
475
|
-
```
|
|
476
|
-
|
|
477
|
-
##### `verify(message, signature)`
|
|
478
|
-
Verifies a message signature using the account's public key.
|
|
479
|
-
|
|
480
|
-
**Parameters:**
|
|
481
|
-
- `message` (string): Original message
|
|
482
|
-
- `signature` (string): Signature as hex string
|
|
483
|
-
|
|
484
|
-
**Returns:** `Promise<boolean>` - True if signature is valid
|
|
485
|
-
|
|
486
|
-
**Example:**
|
|
487
|
-
```javascript
|
|
488
|
-
const isValid = await account.verify('Hello ERC-4337!', signature)
|
|
489
|
-
console.log('Signature valid:', isValid)
|
|
490
|
-
```
|
|
491
|
-
|
|
492
|
-
##### `verifyTypedData(typedData, signature)`
|
|
493
|
-
Verifies a typed data signature against the account's address.
|
|
494
|
-
|
|
495
|
-
**Parameters:**
|
|
496
|
-
- `typedData` (object):
|
|
497
|
-
- `domain` (object): The EIP-712 domain separator
|
|
498
|
-
- `types` (object): The type definitions
|
|
499
|
-
- `message` (object): The structured message that was signed
|
|
500
|
-
- `signature` (string): The signature to verify
|
|
501
|
-
|
|
502
|
-
**Returns:** `Promise<boolean>` - True if the signature is valid
|
|
503
|
-
|
|
504
|
-
**Example:**
|
|
505
|
-
```javascript
|
|
506
|
-
const isValid = await account.verifyTypedData(
|
|
507
|
-
{
|
|
508
|
-
domain: {
|
|
509
|
-
name: 'MyDApp',
|
|
510
|
-
version: '1',
|
|
511
|
-
chainId: 1,
|
|
512
|
-
verifyingContract: '0x...'
|
|
513
|
-
},
|
|
514
|
-
types: {
|
|
515
|
-
Transfer: [
|
|
516
|
-
{ name: 'to', type: 'address' },
|
|
517
|
-
{ name: 'amount', type: 'uint256' }
|
|
518
|
-
]
|
|
519
|
-
},
|
|
520
|
-
message: {
|
|
521
|
-
to: '0x1234567890abcdef1234567890abcdef12345678',
|
|
522
|
-
amount: '1000000'
|
|
523
|
-
}
|
|
524
|
-
},
|
|
525
|
-
signature
|
|
526
|
-
)
|
|
527
|
-
console.log('Typed data signature valid:', isValid)
|
|
528
|
-
```
|
|
529
|
-
|
|
530
|
-
##### `sendTransaction(tx)`
|
|
531
|
-
Sends a transaction via UserOperation through the ERC-4337 bundler.
|
|
532
|
-
|
|
533
|
-
**Parameters:**
|
|
534
|
-
- `tx` (object | object[]): The transaction object, or an array of multiple transactions to send in batch.
|
|
535
|
-
- `to` (string): Recipient address
|
|
536
|
-
- `value` (number | bigint): Amount in wei
|
|
537
|
-
- `data` (string, optional): Transaction data in hex format
|
|
538
|
-
- `gasLimit` (number | bigint, optional): Maximum gas units for the UserOperation
|
|
539
|
-
- `maxFeePerGas` (number | bigint, optional): EIP-1559 max fee per gas in wei
|
|
540
|
-
- `maxPriorityFeePerGas` (number | bigint, optional): EIP-1559 max priority fee per gas in wei
|
|
541
|
-
- `config` (object, optional): If set, overrides the given configuration options. The provided fields are merged with the constructor configuration (i.e. only the specified properties are overridden). The merged configuration is validated to ensure all required fields for the resulting gas payment mode are present. Accepts any combination of fields from `EvmErc4337WalletPaymasterTokenConfig`, `EvmErc4337WalletSponsorshipPolicyConfig`, or `EvmErc4337WalletNativeCoinsConfig`.
|
|
542
|
-
- `isSponsored` (boolean, optional): Override sponsorship setting
|
|
543
|
-
- `useNativeCoins` (boolean, optional): Override to use native coins for gas
|
|
544
|
-
- `paymasterUrl` (string, optional): Override paymaster service URL
|
|
545
|
-
- `paymasterAddress` (string, optional): Override paymaster smart contract address
|
|
546
|
-
- `paymasterToken` (object, optional): Override paymaster token
|
|
547
|
-
- `sponsorshipPolicyId` (string, optional): Override sponsorship policy ID
|
|
548
|
-
|
|
549
|
-
**Returns:** `Promise<{hash: string, fee: bigint}>` - Object containing UserOperation hash and total fee (in wei)
|
|
550
|
-
|
|
551
|
-
**Example:**
|
|
552
|
-
```javascript
|
|
553
|
-
const result = await account.sendTransaction({
|
|
554
|
-
to: '0x742C4265F5Ba4F8E0842e2b9EfE66302F7a13B6F',
|
|
555
|
-
value: 1000000000000000000n, // 1 ETH in wei
|
|
556
|
-
maxFeePerGas: 20000000000n, // 20 gwei
|
|
557
|
-
maxPriorityFeePerGas: 2000000000n // 2 gwei
|
|
558
|
-
})
|
|
559
|
-
console.log('UserOperation hash:', result.hash)
|
|
560
|
-
console.log('Total fee paid:', result.fee, 'wei')
|
|
561
|
-
|
|
562
|
-
// Send sponsored transaction (overrides constructor config)
|
|
563
|
-
const sponsoredResult = await account.sendTransaction({
|
|
564
|
-
to: '0x742C4265F5Ba4F8E0842e2b9EfE66302F7a13B6F',
|
|
565
|
-
value: 1000000000000000000n
|
|
566
|
-
}, {
|
|
567
|
-
isSponsored: true,
|
|
568
|
-
sponsorshipPolicyId: 'POLICY_ID'
|
|
569
|
-
})
|
|
570
|
-
console.log('Sponsored hash:', sponsoredResult.hash)
|
|
571
|
-
|
|
572
|
-
// Send transaction using native coins for gas
|
|
573
|
-
const nativeResult = await account.sendTransaction({
|
|
574
|
-
to: '0x742C4265F5Ba4F8E0842e2b9EfE66302F7a13B6F',
|
|
575
|
-
value: 1000000000000000000n
|
|
576
|
-
}, {
|
|
577
|
-
useNativeCoins: true
|
|
578
|
-
})
|
|
579
|
-
console.log('Native gas hash:', nativeResult.hash)
|
|
580
|
-
```
|
|
581
|
-
|
|
582
|
-
##### `quoteSendTransaction(tx, config)`
|
|
583
|
-
Estimates the fee for a UserOperation without submitting it to the bundler.
|
|
584
|
-
|
|
585
|
-
**Parameters:**
|
|
586
|
-
- `tx` (object | object[]): Same as sendTransaction `tx` parameter.
|
|
587
|
-
- `config` (object, optional): Same as sendTransaction `config` parameter — overrides the given configuration options by merging with the constructor configuration.
|
|
588
|
-
|
|
589
|
-
**Returns:** `Promise<{fee: bigint}>` - Object containing estimated total fee (in wei)
|
|
590
|
-
|
|
591
|
-
**Example:**
|
|
592
|
-
```javascript
|
|
593
|
-
const quote = await account.quoteSendTransaction({
|
|
594
|
-
to: '0x742C4265F5Ba4F8E0842e2b9EfE66302F7a13B6F',
|
|
595
|
-
value: 1000000000000000000n // 1 ETH in wei
|
|
596
|
-
})
|
|
597
|
-
console.log('Estimated UserOperation fee:', quote.fee, 'wei')
|
|
598
|
-
console.log('Estimated fee in ETH:', Number(quote.fee) / 1e18)
|
|
599
|
-
|
|
600
|
-
// Quote with native coins gas payment
|
|
601
|
-
const nativeQuote = await account.quoteSendTransaction({
|
|
602
|
-
to: '0x742C4265F5Ba4F8E0842e2b9EfE66302F7a13B6F',
|
|
603
|
-
value: 1000000000000000000n
|
|
604
|
-
}, { useNativeCoins: true })
|
|
605
|
-
console.log('Estimated native gas fee:', nativeQuote.fee, 'wei')
|
|
606
|
-
```
|
|
607
|
-
|
|
608
|
-
##### `transfer(options, config)`
|
|
609
|
-
Transfers ERC20 tokens via UserOperation through the bundler.
|
|
610
|
-
|
|
611
|
-
**Parameters:**
|
|
612
|
-
- `options` (object): Transfer options
|
|
613
|
-
- `token` (string): ERC20 token contract address
|
|
614
|
-
- `recipient` (string): Recipient address
|
|
615
|
-
- `amount` (number | bigint): Amount in token's smallest unit
|
|
616
|
-
- `config` (object, optional): Same as sendTransaction `config` parameter — overrides the given configuration options by merging with the constructor configuration.
|
|
617
|
-
|
|
618
|
-
**Returns:** `Promise<{hash: string, fee: bigint}>` - Object containing UserOperation hash and fee (in wei)
|
|
619
|
-
|
|
620
|
-
**Example:**
|
|
621
|
-
```javascript
|
|
622
|
-
const result = await account.transfer({
|
|
623
|
-
token: '0xdAC17F958D2ee523a2206206994597C13D831ec7', // USDT
|
|
624
|
-
recipient: '0x742C4265F5Ba4F8E0842e2b9EfE66302F7a13B6F',
|
|
625
|
-
amount: 1000000n // 1 USDT (6 decimals)
|
|
626
|
-
})
|
|
627
|
-
console.log('UserOperation hash:', result.hash)
|
|
628
|
-
console.log('Gas fee paid:', result.fee, 'wei')
|
|
629
|
-
|
|
630
|
-
// Send sponsored token transfer
|
|
631
|
-
const sponsoredTransfer = await account.transfer({
|
|
632
|
-
token: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
|
|
633
|
-
recipient: '0x742C4265F5Ba4F8E0842e2b9EfE66302F7a13B6F',
|
|
634
|
-
amount: 1000000n
|
|
635
|
-
}, {
|
|
636
|
-
isSponsored: true,
|
|
637
|
-
sponsorshipPolicyId: 'POLICY_ID'
|
|
638
|
-
})
|
|
639
|
-
console.log('Sponsored transfer hash:', sponsoredTransfer.hash)
|
|
640
|
-
|
|
641
|
-
// Transfer using native coins for gas
|
|
642
|
-
const nativeTransfer = await account.transfer({
|
|
643
|
-
token: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
|
|
644
|
-
recipient: '0x742C4265F5Ba4F8E0842e2b9EfE66302F7a13B6F',
|
|
645
|
-
amount: 1000000n
|
|
646
|
-
}, {
|
|
647
|
-
useNativeCoins: true
|
|
648
|
-
})
|
|
649
|
-
console.log('Native gas transfer hash:', nativeTransfer.hash)
|
|
650
|
-
```
|
|
651
|
-
|
|
652
|
-
##### `quoteTransfer(options, config)`
|
|
653
|
-
Estimates the fee for an ERC20 token transfer UserOperation without submitting it.
|
|
654
|
-
|
|
655
|
-
**Parameters:**
|
|
656
|
-
- `options` (object): Same as transfer `options` parameter.
|
|
657
|
-
- `config` (object, optional): Same as sendTransaction `config` parameter — overrides the given configuration options by merging with the constructor configuration.
|
|
658
|
-
|
|
659
|
-
**Returns:** `Promise<{fee: bigint}>` - Object containing estimated fee (in wei)
|
|
660
|
-
|
|
661
|
-
**Example:**
|
|
662
|
-
```javascript
|
|
663
|
-
const quote = await account.quoteTransfer({
|
|
664
|
-
token: '0xdAC17F958D2ee523a2206206994597C13D831ec7', // USDT
|
|
665
|
-
recipient: '0x742C4265F5Ba4F8E0842e2b9EfE66302F7a13B6F',
|
|
666
|
-
amount: 1000000n // 1 USDT (6 decimals)
|
|
667
|
-
})
|
|
668
|
-
console.log('Estimated transfer fee:', quote.fee, 'wei')
|
|
669
|
-
```
|
|
670
|
-
|
|
671
|
-
##### `getBalance()`
|
|
672
|
-
Returns the smart contract wallet's native token balance (e.g., ETH, MATIC, etc.) in wei.
|
|
673
|
-
|
|
674
|
-
**Returns:** `Promise<bigint>` - Balance in wei
|
|
675
|
-
|
|
676
|
-
**Example:**
|
|
677
|
-
```javascript
|
|
678
|
-
const balance = await account.getBalance()
|
|
679
|
-
console.log('Smart account balance:', balance, 'wei')
|
|
680
|
-
console.log('Balance in ETH:', Number(balance) / 1e18)
|
|
681
|
-
```
|
|
682
|
-
|
|
683
|
-
##### `getTokenBalance(tokenAddress)`
|
|
684
|
-
Returns the smart contract wallet's balance of a specific ERC20 token.
|
|
685
|
-
|
|
686
|
-
**Parameters:**
|
|
687
|
-
- `tokenAddress` (string): The ERC20 token contract address
|
|
688
|
-
|
|
689
|
-
**Returns:** `Promise<bigint>` - Token balance in token's smallest unit
|
|
690
|
-
|
|
691
|
-
**Example:**
|
|
692
|
-
```javascript
|
|
693
|
-
// Get USDT balance (6 decimals)
|
|
694
|
-
const usdtBalance = await account.getTokenBalance('0xdAC17F958D2ee523a2206206994597C13D831ec7')
|
|
695
|
-
console.log('Smart account USDT balance:', Number(usdtBalance) / 1e6)
|
|
696
44
|
```
|
|
697
45
|
|
|
698
|
-
|
|
699
|
-
Disposes the wallet account, securely erasing the private key from memory.
|
|
46
|
+
## Key Capabilities
|
|
700
47
|
|
|
701
|
-
**
|
|
702
|
-
|
|
703
|
-
**
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
| Property | Type | Description |
|
|
712
|
-
|----------|------|-------------|
|
|
713
|
-
| `index` | `number` | The derivation path's index of this account |
|
|
714
|
-
| `path` | `string` | The full derivation path of this account |
|
|
715
|
-
| `keyPair` | `object` | The account's key pair (⚠️ Contains sensitive data) |
|
|
716
|
-
|
|
717
|
-
⚠️ **Security Note**: The `keyPair` property contains sensitive cryptographic material. Never log, display, or expose the private key.
|
|
718
|
-
|
|
719
|
-
### WalletAccountReadOnlyEvmErc4337
|
|
720
|
-
|
|
721
|
-
Represents a read-only ERC-4337 wallet account.
|
|
722
|
-
|
|
723
|
-
#### Constructor
|
|
724
|
-
|
|
725
|
-
```javascript
|
|
726
|
-
new WalletAccountReadOnlyEvmErc4337(address, config)
|
|
727
|
-
```
|
|
728
|
-
|
|
729
|
-
**Parameters:**
|
|
730
|
-
- `address` (string): The smart contract wallet address
|
|
731
|
-
- `config` (object): Configuration object. Same configuration union as `WalletManagerEvmErc4337` (excluding `transferMaxFee`) — see [constructor parameters](#constructor) for the full description of common fields and the three gas payment modes.
|
|
732
|
-
|
|
733
|
-
#### Methods
|
|
734
|
-
|
|
735
|
-
| Method | Description | Returns |
|
|
736
|
-
|--------|-------------|---------|
|
|
737
|
-
| `predictSafeAddress(owner, config)` | Static method to predict Safe address for an EOA | `string` |
|
|
738
|
-
| `getBalance()` | Returns the native token balance (in wei) | `Promise<bigint>` |
|
|
739
|
-
| `getTokenBalance(tokenAddress)` | Returns the balance of a specific ERC20 token | `Promise<bigint>` |
|
|
740
|
-
| `getPaymasterTokenBalance()` | Returns the paymaster token balance | `Promise<bigint>` |
|
|
741
|
-
| `quoteSendTransaction(tx, config)` | Estimates the fee for a UserOperation | `Promise<{fee: bigint}>` |
|
|
742
|
-
| `quoteTransfer(options, config)` | Estimates the fee for an ERC20 transfer | `Promise<{fee: bigint}>` |
|
|
743
|
-
| `verify(message, signature)` | Verifies a message signature | `Promise<boolean>` |
|
|
744
|
-
| `verifyTypedData(typedData, signature)` | Verifies a typed data signature | `Promise<boolean>` |
|
|
745
|
-
|
|
746
|
-
##### `predictSafeAddress(owner, config)` (static)
|
|
747
|
-
Predicts the Safe smart contract address for a given EOA owner without requiring network calls.
|
|
748
|
-
|
|
749
|
-
**Parameters:**
|
|
750
|
-
- `owner` (string): The EOA address that will own the Safe
|
|
751
|
-
- `config` (object): Configuration object
|
|
752
|
-
- `chainId` (number): Chain ID of the target network
|
|
753
|
-
- `safeModulesVersion` (string, optional): Safe modules version (e.g., "0.3.0")
|
|
754
|
-
|
|
755
|
-
**Returns:** `string` - The predicted Safe address
|
|
756
|
-
|
|
757
|
-
**Example:**
|
|
758
|
-
```javascript
|
|
759
|
-
const safeAddress = WalletAccountReadOnlyEvmErc4337.predictSafeAddress(
|
|
760
|
-
'0x742C4265F5Ba4F8E0842e2b9EfE66302F7a13B6F',
|
|
761
|
-
{ chainId: 1, safeModulesVersion: '0.3.0' }
|
|
762
|
-
)
|
|
763
|
-
console.log('Predicted Safe address:', safeAddress)
|
|
764
|
-
```
|
|
765
|
-
|
|
766
|
-
##### `getBalance()`
|
|
767
|
-
Returns the smart contract wallet's native token balance (e.g., ETH, MATIC, etc.) in wei.
|
|
768
|
-
|
|
769
|
-
**Returns:** `Promise<bigint>` - Balance in wei
|
|
770
|
-
|
|
771
|
-
**Example:**
|
|
772
|
-
```javascript
|
|
773
|
-
const balance = await readOnlyAccount.getBalance()
|
|
774
|
-
console.log('Smart account balance:', balance, 'wei')
|
|
775
|
-
console.log('Balance in ETH:', Number(balance) / 1e18)
|
|
776
|
-
```
|
|
777
|
-
|
|
778
|
-
##### `getTokenBalance(tokenAddress)`
|
|
779
|
-
Returns the smart contract wallet's balance of a specific ERC20 token.
|
|
780
|
-
|
|
781
|
-
**Parameters:**
|
|
782
|
-
- `tokenAddress` (string): The ERC20 token contract address
|
|
783
|
-
|
|
784
|
-
**Returns:** `Promise<bigint>` - Token balance in token's smallest unit
|
|
785
|
-
|
|
786
|
-
**Example:**
|
|
787
|
-
```javascript
|
|
788
|
-
// Get USDT balance (6 decimals) for the smart account
|
|
789
|
-
const usdtBalance = await readOnlyAccount.getTokenBalance('0xdAC17F958D2ee523a2206206994597C13D831ec7')
|
|
790
|
-
console.log('Smart account USDT balance:', Number(usdtBalance) / 1e6)
|
|
791
|
-
```
|
|
792
|
-
|
|
793
|
-
##### `quoteSendTransaction(tx, config)`
|
|
794
|
-
Estimates the fee for a UserOperation without submitting it to the bundler.
|
|
795
|
-
|
|
796
|
-
**Parameters:**
|
|
797
|
-
- `tx` (object | object[]): The transaction object, or an array of multiple transactions to send in batch.
|
|
798
|
-
- `to` (string): Recipient address
|
|
799
|
-
- `value` (number | bigint): Amount in wei
|
|
800
|
-
- `data` (string, optional): Transaction data in hex format
|
|
801
|
-
- `config` (object, optional): If set, overrides the given configuration options by merging with the constructor configuration. See [`sendTransaction` config](#sendtransactiontx-config) for the full list of overridable fields.
|
|
802
|
-
|
|
803
|
-
**Returns:** `Promise<{fee: bigint}>` - Object containing estimated total UserOperation fee (in wei)
|
|
804
|
-
|
|
805
|
-
**Example:**
|
|
806
|
-
```javascript
|
|
807
|
-
const quote = await readOnlyAccount.quoteSendTransaction({
|
|
808
|
-
to: '0x742C4265F5Ba4F8E0842e2b9EfE66302F7a13B6F',
|
|
809
|
-
value: 1000000000000000000n // 1 ETH in wei
|
|
810
|
-
})
|
|
811
|
-
console.log('Estimated UserOperation fee:', quote.fee, 'wei')
|
|
812
|
-
console.log('Estimated fee in ETH:', Number(quote.fee) / 1e18)
|
|
813
|
-
```
|
|
814
|
-
|
|
815
|
-
##### `quoteTransfer(options, config)`
|
|
816
|
-
Estimates the fee for an ERC20 token transfer UserOperation without submitting it to the bundler.
|
|
817
|
-
|
|
818
|
-
**Parameters:**
|
|
819
|
-
- `options` (object): Transfer options
|
|
820
|
-
- `token` (string): ERC20 token contract address
|
|
821
|
-
- `recipient` (string): Recipient address
|
|
822
|
-
- `amount` (number | bigint): Amount in token's smallest unit
|
|
823
|
-
- `config` (object, optional): Same as `quoteSendTransaction` config parameter.
|
|
824
|
-
|
|
825
|
-
**Returns:** `Promise<{fee: bigint}>` - Object containing estimated UserOperation fee (in wei)
|
|
826
|
-
|
|
827
|
-
**Example:**
|
|
828
|
-
```javascript
|
|
829
|
-
const quote = await readOnlyAccount.quoteTransfer({
|
|
830
|
-
token: '0xdAC17F958D2ee523a2206206994597C13D831ec7', // USDT
|
|
831
|
-
recipient: '0x742C4265F5Ba4F8E0842e2b9EfE66302F7a13B6F',
|
|
832
|
-
amount: 1000000n // 1 USDT (6 decimals)
|
|
833
|
-
})
|
|
834
|
-
console.log('Estimated transfer UserOperation fee:', quote.fee, 'wei')
|
|
835
|
-
console.log('Estimated fee in ETH:', Number(quote.fee) / 1e18)
|
|
836
|
-
```
|
|
837
|
-
|
|
838
|
-
##### `verify(message, signature)`
|
|
839
|
-
Verifies a message signature using the account's public key.
|
|
840
|
-
|
|
841
|
-
**Parameters:**
|
|
842
|
-
- `message` (string): Original message
|
|
843
|
-
- `signature` (string): Signature as hex string
|
|
844
|
-
|
|
845
|
-
**Returns:** `Promise<boolean>` - True if signature is valid
|
|
846
|
-
|
|
847
|
-
**Example:**
|
|
848
|
-
```javascript
|
|
849
|
-
const isValid = await readOnlyAccount.verify('Hello ERC-4337!', signature)
|
|
850
|
-
console.log('Signature valid:', isValid)
|
|
851
|
-
```
|
|
852
|
-
|
|
853
|
-
##### `verifyTypedData(typedData, signature)`
|
|
854
|
-
Verifies a typed data signature against the account's address.
|
|
855
|
-
|
|
856
|
-
**Parameters:**
|
|
857
|
-
- `typedData` (object):
|
|
858
|
-
- `domain` (object): The EIP-712 domain separator
|
|
859
|
-
- `types` (object): The type definitions
|
|
860
|
-
- `message` (object): The structured message that was signed
|
|
861
|
-
- `signature` (string): The signature to verify
|
|
862
|
-
|
|
863
|
-
**Returns:** `Promise<boolean>` - True if the signature is valid
|
|
864
|
-
|
|
865
|
-
**Example:**
|
|
866
|
-
```javascript
|
|
867
|
-
const isValid = await account.verifyTypedData(
|
|
868
|
-
{
|
|
869
|
-
domain: {
|
|
870
|
-
name: 'MyDApp',
|
|
871
|
-
version: '1',
|
|
872
|
-
chainId: 1,
|
|
873
|
-
verifyingContract: '0x...'
|
|
874
|
-
},
|
|
875
|
-
types: {
|
|
876
|
-
Transfer: [
|
|
877
|
-
{ name: 'to', type: 'address' },
|
|
878
|
-
{ name: 'amount', type: 'uint256' }
|
|
879
|
-
]
|
|
880
|
-
},
|
|
881
|
-
message: {
|
|
882
|
-
to: '0x1234567890abcdef1234567890abcdef12345678',
|
|
883
|
-
amount: '1000000'
|
|
884
|
-
}
|
|
885
|
-
},
|
|
886
|
-
signature
|
|
887
|
-
)
|
|
888
|
-
console.log('Typed data signature valid:', isValid)
|
|
889
|
-
```
|
|
890
|
-
|
|
891
|
-
## 🌐 Supported Networks
|
|
892
|
-
|
|
893
|
-
This package works with any EVM-compatible blockchain that supports ERC-4337, including:
|
|
894
|
-
|
|
895
|
-
- **Ethereum Mainnet**
|
|
896
|
-
- **Ethereum Testnets** (Sepolia, etc.)
|
|
897
|
-
- **Layer 2 Networks** (Arbitrum, Optimism, etc.)
|
|
898
|
-
- **Other EVM Chains** (Polygon, Avalanche C-Chain, etc.)
|
|
899
|
-
|
|
900
|
-
## 🔒 Security Considerations
|
|
901
|
-
|
|
902
|
-
- **Seed Phrase Security**: Always store your seed phrase securely and never share it
|
|
903
|
-
- **Private Key Management**: The package handles private keys internally with memory safety features
|
|
904
|
-
- **Smart Contract Security**:
|
|
905
|
-
- Verify EntryPoint contract addresses
|
|
906
|
-
- Use audited account implementation contracts
|
|
907
|
-
- Validate factory contract addresses
|
|
908
|
-
- **Bundler Security**:
|
|
909
|
-
- Use trusted bundler services
|
|
910
|
-
- Validate UserOperation contents before signing
|
|
911
|
-
- Monitor bundler responses for unexpected behavior
|
|
912
|
-
- **Memory Cleanup**: Use the `dispose()` method to clear private keys from memory when done
|
|
913
|
-
- **Fee Limits**: Set `transferMaxFee` to prevent excessive transaction fees
|
|
914
|
-
- **Gas Estimation**: Always estimate gas before sending UserOperations
|
|
915
|
-
- **Contract Interactions**:
|
|
916
|
-
- Verify contract addresses and token decimals before transfers
|
|
917
|
-
- Review UserOperation calldata before signing
|
|
918
|
-
- **Network Validation**: Ensure correct EntryPoint and factory addresses for each network
|
|
48
|
+
- **ERC-4337 Account Abstraction**: Full implementation of the ERC-4337 standard
|
|
49
|
+
- **Multiple Gas Payment Modes**: Pay fees with native coins, ERC-20 tokens via paymaster, or sponsored transactions
|
|
50
|
+
- **UserOperation Management**: Create and send UserOperations through bundlers
|
|
51
|
+
- **BIP-44 Derivation Paths**: Standard Ethereum derivation (m/44'/60')
|
|
52
|
+
- **Multi-Account Management**: Derive multiple smart accounts from a single seed phrase
|
|
53
|
+
- **ERC-20 Token Support**: Query balances and transfer tokens via UserOperations
|
|
54
|
+
- **Message Signing**: Sign and verify messages with the underlying EOA key
|
|
55
|
+
- **Per-Call Config Overrides**: Switch gas payment modes on a per-transaction basis
|
|
56
|
+
- **Secure Memory Disposal**: Clear private keys from memory when done
|
|
919
57
|
|
|
920
|
-
##
|
|
58
|
+
## Compatibility
|
|
921
59
|
|
|
922
|
-
|
|
60
|
+
- **Ethereum Mainnet** and testnets (Sepolia)
|
|
61
|
+
- **Layer 2 Networks**: Arbitrum, Optimism, Base
|
|
62
|
+
- **Other EVM Chains**: Polygon, Avalanche C-Chain, and any EVM-compatible chain with ERC-4337 support
|
|
923
63
|
|
|
924
|
-
|
|
925
|
-
# Install dependencies
|
|
926
|
-
npm install
|
|
64
|
+
## Documentation
|
|
927
65
|
|
|
928
|
-
|
|
929
|
-
|
|
66
|
+
| Topic | Description | Link |
|
|
67
|
+
|-------|-------------|------|
|
|
68
|
+
| Overview | Module overview and feature summary | [Wallet EVM ERC-4337 Overview](https://docs.wdk.tether.io/sdk/wallet-modules/wallet-evm-erc-4337) |
|
|
69
|
+
| Usage | End-to-end integration walkthrough | [Wallet EVM ERC-4337 Usage](https://docs.wdk.tether.io/sdk/wallet-modules/wallet-evm-erc-4337/usage) |
|
|
70
|
+
| 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) |
|
|
71
|
+
| 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) |
|
|
930
72
|
|
|
931
|
-
|
|
932
|
-
npm run lint
|
|
73
|
+
## Examples
|
|
933
74
|
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
75
|
+
| Example | Description |
|
|
76
|
+
|---------|-------------|
|
|
77
|
+
| [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 |
|
|
78
|
+
| [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 |
|
|
79
|
+
| [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 |
|
|
80
|
+
| [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 |
|
|
81
|
+
| [Send Transaction](https://github.com/tetherto/wdk-examples/blob/main/wallet-evm-erc-4337/send-transaction.ts) | Send transactions via UserOperations through the bundler |
|
|
82
|
+
| [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 |
|
|
83
|
+
| [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 |
|
|
84
|
+
| [Fee Management](https://github.com/tetherto/wdk-examples/blob/main/wallet-evm-erc-4337/fee-management.ts) | Retrieve current bundler fee rates |
|
|
85
|
+
| [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 |
|
|
937
86
|
|
|
938
|
-
|
|
87
|
+
> For detailed walkthroughs, see the [Usage Guide](https://docs.wdk.tether.io/sdk/wallet-modules/wallet-evm-erc-4337/usage).
|
|
88
|
+
> See all runnable examples in the [wdk-examples](https://github.com/tetherto/wdk-examples) repository.
|
|
939
89
|
|
|
940
|
-
|
|
941
|
-
# Run tests
|
|
942
|
-
npm test
|
|
90
|
+
## Community
|
|
943
91
|
|
|
944
|
-
|
|
945
|
-
npm run test:coverage
|
|
946
|
-
```
|
|
92
|
+
Join the [WDK Discord](https://discord.gg/arYXDhHB2w) to connect with other developers.
|
|
947
93
|
|
|
948
|
-
##
|
|
94
|
+
## Support
|
|
949
95
|
|
|
950
|
-
|
|
96
|
+
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).
|
|
951
97
|
|
|
952
|
-
##
|
|
98
|
+
## Contributing
|
|
953
99
|
|
|
954
100
|
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
955
101
|
|
|
956
|
-
##
|
|
102
|
+
## License
|
|
957
103
|
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
---
|
|
104
|
+
This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.
|