@tetherto/wdk-wallet-evm 1.0.0-beta.2 → 1.0.0-beta.20
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/AGENTS.md +50 -0
- package/README.md +174 -224
- package/bare.js +3 -3
- package/{hardhat.config.cjs → hardhat.config.js} +4 -3
- package/index.js +23 -1
- package/package.json +29 -14
- package/src/memory-safe/hd-node-wallet.js +5 -4
- package/src/memory-safe/signing-key.js +4 -3
- package/src/multicall.js +75 -0
- package/src/signers/index.js +25 -0
- package/src/signers/private-key-signer-evm.js +156 -0
- package/src/signers/seed-signer-evm.js +314 -0
- package/src/utils/tx-populator-evm.js +202 -0
- package/src/wallet-account-evm.js +272 -63
- package/src/wallet-account-read-only-evm.js +470 -33
- package/src/wallet-manager-evm.js +96 -39
- package/types/index.d.ts +20 -1
- package/types/src/signers/index.d.ts +3 -0
- package/types/src/signers/private-key-signer-evm.d.ts +81 -0
- package/types/src/signers/seed-signer-evm.d.ts +187 -0
- package/types/src/utils/tx-populator-evm.d.ts +85 -0
- package/types/src/wallet-account-evm.d.ts +131 -22
- package/types/src/wallet-account-read-only-evm.d.ts +226 -14
- package/types/src/wallet-manager-evm.d.ts +43 -19
package/AGENTS.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Agent Guide
|
|
2
|
+
|
|
3
|
+
This repository is part of the Tether WDK (Wallet Development Kit) ecosystem. It follows strict coding conventions and tooling standards to ensure consistency, reliability, and cross-platform compatibility (Node.js and Bare runtime).
|
|
4
|
+
|
|
5
|
+
## Project Overview
|
|
6
|
+
- **Architecture:** Modular architecture with clear separation between Core, Wallet managers, and Protocols.
|
|
7
|
+
- **Runtime:** Supports both Node.js and Bare runtime.
|
|
8
|
+
|
|
9
|
+
## Tech Stack & Tooling
|
|
10
|
+
- **Language:** JavaScript (ES2015+).
|
|
11
|
+
- **Module System:** ES Modules (`"type": "module"` in package.json).
|
|
12
|
+
- **Type Checking:** TypeScript is used purely for generating type declarations (`.d.ts`). The source code remains JavaScript.
|
|
13
|
+
- Command: `npm run build:types`
|
|
14
|
+
- **Linting:** `standard` (JavaScript Standard Style).
|
|
15
|
+
- Command: `npm run lint` / `npm run lint:fix`
|
|
16
|
+
- **Testing:** `jest` (configured with `experimental-vm-modules` for ESM support).
|
|
17
|
+
- Command: `npm test`
|
|
18
|
+
- **Dependencies:** `cross-env` is consistently used for environment variable management in scripts.
|
|
19
|
+
|
|
20
|
+
## Coding Conventions
|
|
21
|
+
- **File Naming:** Kebab-case (e.g., `wallet-manager.js`).
|
|
22
|
+
- **Class Naming:** PascalCase (e.g., `WdkManager`).
|
|
23
|
+
- **Private Members:** Prefixed with `_` (underscore) and explicitly documented with `@private`.
|
|
24
|
+
- **Imports:** Explicit file extensions are mandatory (e.g., `import ... from './file.js'`).
|
|
25
|
+
- **Copyright:** All source files must include the standard Tether copyright header.
|
|
26
|
+
|
|
27
|
+
## Documentation (JSDoc)
|
|
28
|
+
Source code must be strictly typed using JSDoc comments to support the `build:types` process.
|
|
29
|
+
- **Types:** Use `@typedef` to define or import types.
|
|
30
|
+
- **Methods:** Use `@param`, `@returns`, `@throws`.
|
|
31
|
+
- **Generics:** Use `@template`.
|
|
32
|
+
|
|
33
|
+
## Development Workflow
|
|
34
|
+
1. **Install:** `npm install`
|
|
35
|
+
2. **Lint:** `npm run lint`
|
|
36
|
+
3. **Test:** `npm test`
|
|
37
|
+
4. **Build Types:** `npm run build:types`
|
|
38
|
+
|
|
39
|
+
## Key Files
|
|
40
|
+
- `index.js`: Main entry point.
|
|
41
|
+
- `bare.js`: Entry point for Bare runtime optimization.
|
|
42
|
+
- `src/`: Core logic.
|
|
43
|
+
- `types/`: Generated type definitions (do not edit manually).
|
|
44
|
+
|
|
45
|
+
## Repository Specifics
|
|
46
|
+
- **Domain:** EVM Blockchain Wallet Management.
|
|
47
|
+
- **Key Library:** `ethers` (v6).
|
|
48
|
+
- **Standards:** BIP-44 (m/44'/60'), EIP-1559.
|
|
49
|
+
- **Architecture:** Extends base wallet classes to support Ethereum transactions, ERC20 tokens, and fee estimation.
|
|
50
|
+
- **Testing:** Integration tests often use Hardhat.
|
package/README.md
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
# @tetherto/wdk-wallet-evm
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@tetherto/wdk-wallet-evm)
|
|
4
|
+
[](https://www.npmjs.com/package/@tetherto/wdk-wallet-evm)
|
|
5
|
+
[](https://github.com/tetherto/wdk-wallet-evm/blob/main/LICENSE)
|
|
6
|
+
[](https://docs.wdk.tether.io/sdk/wallet-modules/wallet-evm)
|
|
3
7
|
|
|
4
8
|
**Note**: This package is currently in beta. Please test thoroughly in development environments before using in production.
|
|
5
9
|
|
|
6
|
-
|
|
10
|
+
An EVM wallet module for WDK (Wallet Development Kit) by Tether. This package provides a clean API for creating, managing, and interacting with Ethereum-compatible wallets using BIP-39 seed phrases and EVM-specific derivation paths.
|
|
7
11
|
|
|
8
|
-
##
|
|
12
|
+
## About WDK
|
|
9
13
|
|
|
10
|
-
This module is part of the [**WDK (Wallet Development Kit)**](https://
|
|
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.
|
|
11
15
|
|
|
12
|
-
For detailed documentation about the complete WDK ecosystem, visit [docs.
|
|
13
|
-
|
|
14
|
-
## 🌟 Features
|
|
15
|
-
|
|
16
|
-
- **BIP-39 Seed Phrase Support**: Generate and validate BIP-39 mnemonic seed phrases
|
|
17
|
-
- **EVM Derivation Paths**: Support for BIP-44 standard derivation paths for Ethereum (m/44'/60')
|
|
18
|
-
- **Multi-Account Management**: Create and manage multiple accounts from a single seed phrase
|
|
19
|
-
- **Transaction Management**: Send transactions and get fee estimates with EIP-1559 support
|
|
20
|
-
- **ERC20 Support**: Query native token and ERC20 token balances using smart contract interactions
|
|
16
|
+
For detailed documentation about the complete WDK ecosystem, visit [docs.wdk.tether.io](https://docs.wdk.tether.io).
|
|
21
17
|
|
|
22
18
|
## ⬇️ Installation
|
|
23
19
|
|
|
@@ -33,55 +29,102 @@ npm install @tetherto/wdk-wallet-evm
|
|
|
33
29
|
|
|
34
30
|
### Importing from `@tetherto/wdk-wallet-evm`
|
|
35
31
|
|
|
36
|
-
|
|
32
|
+
```javascript
|
|
33
|
+
import WalletManagerEvm, {
|
|
34
|
+
WalletAccountEvm,
|
|
35
|
+
WalletAccountReadOnlyEvm,
|
|
36
|
+
} from '@tetherto/wdk-wallet-evm'
|
|
37
|
+
|
|
38
|
+
// Signers are exported under the /signers subpath
|
|
39
|
+
import {
|
|
40
|
+
SeedSignerEvm,
|
|
41
|
+
PrivateKeySignerEvm,
|
|
42
|
+
} from '@tetherto/wdk-wallet-evm/signers'
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Create a Wallet Manager (seed-based)
|
|
37
46
|
|
|
38
47
|
```javascript
|
|
39
|
-
import WalletManagerEvm
|
|
48
|
+
import WalletManagerEvm from '@tetherto/wdk-wallet-evm'
|
|
49
|
+
import { SeedSignerEvm } from '@tetherto/wdk-wallet-evm/signers'
|
|
40
50
|
|
|
41
51
|
// Use a BIP-39 seed phrase (replace with your own secure phrase)
|
|
42
|
-
const seedPhrase =
|
|
52
|
+
const seedPhrase =
|
|
53
|
+
'test only example nut use this real life secret phrase must random'
|
|
43
54
|
|
|
44
|
-
// Create
|
|
45
|
-
const
|
|
55
|
+
// Create a root signer from the seed phrase
|
|
56
|
+
const root = new SeedSignerEvm(seedPhrase)
|
|
57
|
+
|
|
58
|
+
// Create wallet manager with provider config (provider is required for chain ops)
|
|
59
|
+
const wallet = new WalletManagerEvm(root, {
|
|
46
60
|
// Option 1: Using RPC URL
|
|
47
|
-
provider: 'https://
|
|
48
|
-
transferMaxFee:
|
|
61
|
+
provider: 'https://sepolia.drpc.org', // any EVM RPC
|
|
62
|
+
transferMaxFee: 100000000000000n, // Optional: max fee in wei (BigInt)
|
|
49
63
|
})
|
|
50
64
|
|
|
51
65
|
// OR
|
|
52
66
|
|
|
53
67
|
// Option 2: Using EIP-1193 provider (e.g., from browser wallet)
|
|
54
|
-
const wallet2 = new WalletManagerEvm(
|
|
68
|
+
const wallet2 = new WalletManagerEvm(root, {
|
|
55
69
|
provider: window.ethereum, // EIP-1193 provider
|
|
56
|
-
transferMaxFee:
|
|
70
|
+
transferMaxFee: 100000000000000n, // Optional
|
|
57
71
|
})
|
|
58
72
|
|
|
59
73
|
// Get a full access account
|
|
60
|
-
const
|
|
74
|
+
const account0 = await wallet.getAccount(0)
|
|
61
75
|
|
|
62
76
|
// Convert to a read-only account
|
|
63
|
-
const readOnlyAccount = await
|
|
77
|
+
const readOnlyAccount = await account0.toReadOnlyAccount()
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Single Account (no manager): Private key
|
|
81
|
+
|
|
82
|
+
```javascript
|
|
83
|
+
import { WalletAccountEvm } from '@tetherto/wdk-wallet-evm'
|
|
84
|
+
import { PrivateKeySignerEvm } from '@tetherto/wdk-wallet-evm/signers'
|
|
85
|
+
|
|
86
|
+
// From a raw private key (hex string or bytes)
|
|
87
|
+
const pkSigner = new PrivateKeySignerEvm('0x0123...abcd')
|
|
88
|
+
const pkAccount = new WalletAccountEvm(pkSigner, {
|
|
89
|
+
provider: 'https://eth-mainnet.g.alchemy.com/v2/your-api-key',
|
|
90
|
+
})
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Single Account (no manager): Seed + path
|
|
94
|
+
|
|
95
|
+
```javascript
|
|
96
|
+
import { WalletAccountEvm } from '@tetherto/wdk-wallet-evm'
|
|
97
|
+
|
|
98
|
+
// From a BIP-39 seed phrase (or seed bytes) and a BIP-44 derivation path
|
|
99
|
+
const account = new WalletAccountEvm(mnemonic, "0'/0/0", {
|
|
100
|
+
provider: 'https://eth-mainnet.g.alchemy.com/v2/your-api-key',
|
|
101
|
+
})
|
|
64
102
|
```
|
|
65
103
|
|
|
66
|
-
### Managing Multiple Accounts
|
|
104
|
+
### Managing Multiple Accounts (seed-based manager)
|
|
67
105
|
|
|
68
106
|
```javascript
|
|
69
107
|
import WalletManagerEvm from '@tetherto/wdk-wallet-evm'
|
|
108
|
+
import { SeedSignerEvm } from '@tetherto/wdk-wallet-evm/signers'
|
|
109
|
+
|
|
110
|
+
const root = new SeedSignerEvm(mnemonic)
|
|
111
|
+
const wallet = new WalletManagerEvm(root, {
|
|
112
|
+
provider: 'https://eth-mainnet.g.alchemy.com/v2/your-api-key',
|
|
113
|
+
})
|
|
70
114
|
|
|
71
|
-
// Assume wallet is already created
|
|
72
115
|
// Get the first account (index 0)
|
|
73
|
-
const account = await wallet.getAccount(0)
|
|
74
|
-
const address = await account.getAddress()
|
|
116
|
+
const account = await wallet.getAccount(0) // m/44'/60'/0'/0/0
|
|
117
|
+
const address = await account.getAddress() // 0x...
|
|
75
118
|
console.log('Account 0 address:', address)
|
|
76
119
|
|
|
77
120
|
// Get the second account (index 1)
|
|
78
|
-
const account1 = await wallet.getAccount(1)
|
|
79
|
-
const address1 = await account1.getAddress()
|
|
121
|
+
const account1 = await wallet.getAccount(1) // m/44'/60'/0'/0/1
|
|
122
|
+
const address1 = await account1.getAddress() // 0x...
|
|
80
123
|
console.log('Account 1 address:', address1)
|
|
81
124
|
|
|
82
125
|
// Get account by custom derivation path
|
|
83
126
|
// Full path will be m/44'/60'/0'/0/5
|
|
84
|
-
const customAccount = await wallet.getAccountByPath(
|
|
127
|
+
const customAccount = await wallet.getAccountByPath('0\'/0/5')
|
|
85
128
|
const customAddress = await customAccount.getAddress()
|
|
86
129
|
console.log('Custom account address:', customAddress)
|
|
87
130
|
|
|
@@ -96,17 +139,15 @@ console.log('Custom account address:', customAddress)
|
|
|
96
139
|
For accounts where you have the seed phrase and full access:
|
|
97
140
|
|
|
98
141
|
```javascript
|
|
99
|
-
import WalletManagerEvm from '@tetherto/wdk-wallet-evm'
|
|
100
|
-
|
|
101
142
|
// Assume wallet and account are already created
|
|
102
143
|
// Get native token balance (in wei)
|
|
103
144
|
const balance = await account.getBalance()
|
|
104
145
|
console.log('Native balance:', balance, 'wei') // 1 ETH = 1000000000000000000 wei
|
|
105
146
|
|
|
106
147
|
// Get ERC20 token balance
|
|
107
|
-
const tokenContract = '0x...'
|
|
108
|
-
const tokenBalance = await account.getTokenBalance(tokenContract)
|
|
109
|
-
console.log('Token balance:', tokenBalance)
|
|
148
|
+
const tokenContract = '0x...' // ERC20 contract address
|
|
149
|
+
const tokenBalance = await account.getTokenBalance(tokenContract)
|
|
150
|
+
console.log('Token balance:', tokenBalance)
|
|
110
151
|
|
|
111
152
|
// Note: Provider is required for balance checks
|
|
112
153
|
// Make sure wallet was created with a provider configuration
|
|
@@ -120,8 +161,9 @@ For addresses where you don't have the seed phrase:
|
|
|
120
161
|
import { WalletAccountReadOnlyEvm } from '@tetherto/wdk-wallet-evm'
|
|
121
162
|
|
|
122
163
|
// Create a read-only account
|
|
123
|
-
const readOnlyAccount = new WalletAccountReadOnlyEvm('0x...', {
|
|
124
|
-
|
|
164
|
+
const readOnlyAccount = new WalletAccountReadOnlyEvm('0x...', {
|
|
165
|
+
// Ethereum address
|
|
166
|
+
provider: 'https://sepolia.drpc.org', // Required for balance checks
|
|
125
167
|
})
|
|
126
168
|
|
|
127
169
|
// Check native token balance
|
|
@@ -138,7 +180,7 @@ console.log('Token balance:', tokenBalance)
|
|
|
138
180
|
|
|
139
181
|
### Sending Transactions
|
|
140
182
|
|
|
141
|
-
Send native tokens and estimate fees using `WalletAccountEvm`. Supports EIP-1559 fee
|
|
183
|
+
Send native tokens and estimate fees using `WalletAccountEvm`. Supports EIP-1559 and auto-populates gas/fee fields where possible.
|
|
142
184
|
|
|
143
185
|
```javascript
|
|
144
186
|
// Send native tokens
|
|
@@ -146,8 +188,8 @@ Send native tokens and estimate fees using `WalletAccountEvm`. Supports EIP-1559
|
|
|
146
188
|
const result = await account.sendTransaction({
|
|
147
189
|
to: '0x...', // Recipient address
|
|
148
190
|
value: 1000000000000000000n, // 1 ETH in wei
|
|
149
|
-
maxFeePerGas:
|
|
150
|
-
maxPriorityFeePerGas:
|
|
191
|
+
maxFeePerGas: 30000000000n, // Optional: max fee per gas (in wei)
|
|
192
|
+
maxPriorityFeePerGas: 2000000000n, // Optional: max priority fee per gas (in wei)
|
|
151
193
|
})
|
|
152
194
|
console.log('Transaction hash:', result.hash)
|
|
153
195
|
console.log('Transaction fee:', result.fee, 'wei')
|
|
@@ -157,15 +199,15 @@ const legacyResult = await account.sendTransaction({
|
|
|
157
199
|
to: '0x...',
|
|
158
200
|
value: 1000000000000000000n,
|
|
159
201
|
gasPrice: 20000000000n, // Optional: legacy gas price (in wei)
|
|
160
|
-
gasLimit: 21000 // Optional: gas limit
|
|
202
|
+
gasLimit: 21000, // Optional: gas limit
|
|
161
203
|
})
|
|
162
204
|
|
|
163
205
|
// Get transaction fee estimate
|
|
164
206
|
const quote = await account.quoteSendTransaction({
|
|
165
207
|
to: '0x...',
|
|
166
|
-
value: 1000000000000000000n
|
|
167
|
-
})
|
|
168
|
-
console.log('Estimated fee:', quote.fee, 'wei')
|
|
208
|
+
value: 1000000000000000000n,
|
|
209
|
+
})
|
|
210
|
+
console.log('Estimated fee:', quote.fee, 'wei')
|
|
169
211
|
```
|
|
170
212
|
|
|
171
213
|
### Token Transfers
|
|
@@ -175,25 +217,38 @@ Transfer ERC20 tokens and estimate fees using `WalletAccountEvm`. Uses standard
|
|
|
175
217
|
```javascript
|
|
176
218
|
// Transfer ERC20 tokens
|
|
177
219
|
const transferResult = await account.transfer({
|
|
178
|
-
token: '0x...',
|
|
179
|
-
recipient: '0x...',
|
|
180
|
-
amount: 1000000n
|
|
181
|
-
})
|
|
182
|
-
console.log('Transfer hash:', transferResult.hash)
|
|
183
|
-
console.log('Transfer fee:', transferResult.fee, 'wei')
|
|
220
|
+
token: '0x...', // ERC20 contract address
|
|
221
|
+
recipient: '0x...', // Recipient's address
|
|
222
|
+
amount: 1000000n, // Amount in token's base units (use BigInt for large numbers)
|
|
223
|
+
})
|
|
224
|
+
console.log('Transfer hash:', transferResult.hash)
|
|
225
|
+
console.log('Transfer fee:', transferResult.fee, 'wei')
|
|
184
226
|
|
|
185
227
|
// Quote token transfer fee
|
|
186
228
|
const transferQuote = await account.quoteTransfer({
|
|
187
|
-
token: '0x...',
|
|
188
|
-
recipient: '0x...',
|
|
189
|
-
amount: 1000000n
|
|
229
|
+
token: '0x...', // ERC20 contract address
|
|
230
|
+
recipient: '0x...', // Recipient's address
|
|
231
|
+
amount: 1000000n, // Amount in token's base units
|
|
190
232
|
})
|
|
191
233
|
console.log('Transfer fee estimate:', transferQuote.fee, 'wei')
|
|
192
234
|
```
|
|
193
235
|
|
|
236
|
+
### Token Approvals
|
|
237
|
+
|
|
238
|
+
Approve a spender for a specific amount (uses ERC20 `approve`):
|
|
239
|
+
|
|
240
|
+
```javascript
|
|
241
|
+
const approval = await account.approve({
|
|
242
|
+
token: '0x...', // ERC20 contract
|
|
243
|
+
spender: '0x...', // Spender address
|
|
244
|
+
amount: 1000000n, // Allowance amount in base units
|
|
245
|
+
})
|
|
246
|
+
console.log('Approval tx hash:', approval.hash)
|
|
247
|
+
```
|
|
248
|
+
|
|
194
249
|
### Message Signing and Verification
|
|
195
250
|
|
|
196
|
-
Sign and verify
|
|
251
|
+
Sign messages using `WalletAccountEvm` and verify signatures using `WalletAccountReadOnlyEvm`.
|
|
197
252
|
|
|
198
253
|
```javascript
|
|
199
254
|
// Sign a message
|
|
@@ -201,8 +256,8 @@ const message = 'Hello, Ethereum!'
|
|
|
201
256
|
const signature = await account.sign(message)
|
|
202
257
|
console.log('Signature:', signature)
|
|
203
258
|
|
|
204
|
-
// Verify a signature
|
|
205
|
-
const isValid = await
|
|
259
|
+
// Verify a signature (can use read-only account)
|
|
260
|
+
const isValid = await readOnlyAccount.verify(message, signature)
|
|
206
261
|
console.log('Signature valid:', isValid)
|
|
207
262
|
```
|
|
208
263
|
|
|
@@ -212,9 +267,9 @@ Retrieve current fee rates using `WalletManagerEvm`. Supports EIP-1559 fee model
|
|
|
212
267
|
|
|
213
268
|
```javascript
|
|
214
269
|
// Get current fee rates
|
|
215
|
-
const feeRates = await wallet.getFeeRates()
|
|
216
|
-
console.log('Normal fee rate:', feeRates.normal, 'wei')
|
|
217
|
-
console.log('Fast fee rate:', feeRates.fast, 'wei')
|
|
270
|
+
const feeRates = await wallet.getFeeRates()
|
|
271
|
+
console.log('Normal fee rate:', feeRates.normal, 'wei') // 1.1x base fee
|
|
272
|
+
console.log('Fast fee rate:', feeRates.fast, 'wei') // 2.0x base fee
|
|
218
273
|
```
|
|
219
274
|
|
|
220
275
|
### Memory Management
|
|
@@ -229,192 +284,87 @@ account.dispose()
|
|
|
229
284
|
wallet.dispose()
|
|
230
285
|
```
|
|
231
286
|
|
|
232
|
-
##
|
|
233
|
-
|
|
234
|
-
### Table of Contents
|
|
235
|
-
|
|
236
|
-
### Table of Contents
|
|
237
|
-
|
|
238
|
-
| Class | Description | Methods |
|
|
239
|
-
|-------|-------------|---------|
|
|
240
|
-
| [WalletManagerEvm](#walletmanagerevm) | Main class for managing EVM wallets. Extends `WalletManager` from `@tetherto/wdk-wallet`. | [Constructor](#constructor), [Methods](#methods) |
|
|
241
|
-
| [WalletAccountEvm](#walletaccountevm) | Individual EVM wallet account implementation. Extends `WalletAccountReadOnlyEvm` and implements `IWalletAccount` from `@tetherto/wdk-wallet`. | [Constructor](#constructor-1), [Methods](#methods-1), [Properties](#properties) |
|
|
242
|
-
| [WalletAccountReadOnlyEvm](#walletaccountreadonlyevm) | Read-only EVM wallet account. Extends `WalletAccountReadOnly` from `@tetherto/wdk-wallet`. | [Constructor](#constructor-2), [Methods](#methods-2) |
|
|
243
|
-
|
|
244
|
-
### WalletManagerEvm
|
|
245
|
-
|
|
246
|
-
The main class for managing EVM wallets.
|
|
247
|
-
Extends `WalletManager` from `@tetherto/wdk-wallet`.
|
|
248
|
-
|
|
249
|
-
#### Constructor
|
|
250
|
-
|
|
251
|
-
```javascript
|
|
252
|
-
new WalletManagerEvm(seed, config)
|
|
253
|
-
```
|
|
254
|
-
|
|
255
|
-
**Parameters:**
|
|
256
|
-
- `seed` (string | Uint8Array): BIP-39 mnemonic seed phrase or seed bytes
|
|
257
|
-
- `config` (object, optional): Configuration object
|
|
258
|
-
- `provider` (string | Eip1193Provider): RPC endpoint URL or EIP-1193 provider instance
|
|
259
|
-
- `transferMaxFee` (number | bigint, optional): Maximum fee amount for transfer operations (in wei)
|
|
260
|
-
|
|
261
|
-
**Example:**
|
|
262
|
-
```javascript
|
|
263
|
-
const wallet = new WalletManagerEvm(seedPhrase, {
|
|
264
|
-
provider: 'https://eth-mainnet.g.alchemy.com/v2/your-api-key',
|
|
265
|
-
transferMaxFee: '100000000000000' // Maximum fee in wei
|
|
266
|
-
})
|
|
267
|
-
```
|
|
268
|
-
|
|
269
|
-
#### Methods
|
|
287
|
+
## 🔐 Signers
|
|
270
288
|
|
|
271
|
-
|
|
272
|
-
|--------|-------------|---------|
|
|
273
|
-
| `getAccount(index)` | Returns a wallet account at the specified index | `Promise<WalletAccountEvm>` |
|
|
274
|
-
| `getAccountByPath(path)` | Returns a wallet account at the specified BIP-44 derivation path | `Promise<WalletAccountEvm>` |
|
|
275
|
-
| `getFeeRates()` | Returns current fee rates for transactions | `Promise<{normal: bigint, fast: bigint}>` |
|
|
276
|
-
| `dispose()` | Disposes all wallet accounts, clearing private keys from memory | `void` |
|
|
289
|
+
Signers provide the cryptographic primitives for accounts. There are two signer implementations:
|
|
277
290
|
|
|
278
|
-
|
|
291
|
+
- **SeedSignerEvm (root + child)**: Derives accounts from a BIP-39 seed using the BIP-44 Ethereum path. Can act as a root (for `WalletManagerEvm`) and derive children (for `WalletAccountEvm`).
|
|
292
|
+
- **PrivateKeySignerEvm (child only)**: Wraps a raw private key in a memory-safe buffer. Cannot derive. Use directly with `WalletAccountEvm`. Not supported by `WalletManagerEvm`.
|
|
279
293
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
#### Constructor
|
|
294
|
+
Examples:
|
|
283
295
|
|
|
284
296
|
```javascript
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
| Method | Description | Returns |
|
|
298
|
-
|--------|-------------|---------|
|
|
299
|
-
| `getAddress()` | Returns the account's address | `Promise<string>` |
|
|
300
|
-
| `sign(message)` | Signs a message using the account's private key | `Promise<string>` |
|
|
301
|
-
| `verify(message, signature)` | Verifies a message signature | `Promise<boolean>` |
|
|
302
|
-
| `sendTransaction(tx)` | Sends an EVM transaction | `Promise<{hash: string, fee: bigint}>` |
|
|
303
|
-
| `quoteSendTransaction(tx)` | Estimates the fee for an EVM transaction | `Promise<{fee: bigint}>` |
|
|
304
|
-
| `transfer(options)` | Transfers ERC20 tokens to another address | `Promise<{hash: string, fee: bigint}>` |
|
|
305
|
-
| `quoteTransfer(options)` | Estimates the fee for an ERC20 transfer | `Promise<{fee: bigint}>` |
|
|
306
|
-
| `getBalance()` | Returns the native token balance (in wei) | `Promise<bigint>` |
|
|
307
|
-
| `getTokenBalance(tokenAddress)` | Returns the balance of a specific ERC20 token | `Promise<bigint>` |
|
|
308
|
-
| `dispose()` | Disposes the wallet account, clearing private keys from memory | `void` |
|
|
309
|
-
|
|
310
|
-
##### `sendTransaction(tx)`
|
|
311
|
-
Sends an EVM transaction.
|
|
312
|
-
|
|
313
|
-
**Parameters:**
|
|
314
|
-
- `tx` (object): The transaction object
|
|
315
|
-
- `to` (string): Recipient address
|
|
316
|
-
- `value` (number | bigint): Amount in wei
|
|
317
|
-
- `data` (string, optional): Transaction data in hex format
|
|
318
|
-
- `gasLimit` (number | bigint, optional): Maximum gas units
|
|
319
|
-
- `gasPrice` (number | bigint, optional): Legacy gas price in wei
|
|
320
|
-
- `maxFeePerGas` (number | bigint, optional): EIP-1559 max fee per gas in wei
|
|
321
|
-
- `maxPriorityFeePerGas` (number | bigint, optional): EIP-1559 max priority fee per gas in wei
|
|
322
|
-
|
|
323
|
-
**Returns:** `Promise<{hash: string, fee: bigint}>` - Object containing hash and fee (in wei)
|
|
324
|
-
|
|
325
|
-
#### Properties
|
|
326
|
-
|
|
327
|
-
| Property | Type | Description |
|
|
328
|
-
|----------|------|-------------|
|
|
329
|
-
| `index` | `number` | The derivation path's index of this account |
|
|
330
|
-
| `path` | `string` | The full derivation path of this account |
|
|
331
|
-
| `keyPair` | `object` | The account's key pair (⚠️ Contains sensitive data) |
|
|
332
|
-
|
|
333
|
-
⚠️ **Security Note**: The `keyPair` property contains sensitive cryptographic material. Never log, display, or expose the private key.
|
|
334
|
-
|
|
335
|
-
### WalletAccountReadOnlyEvm
|
|
336
|
-
|
|
337
|
-
Represents a read-only wallet account.
|
|
338
|
-
|
|
339
|
-
#### Constructor
|
|
340
|
-
|
|
341
|
-
```javascript
|
|
342
|
-
new WalletAccountReadOnlyEvm(address, config)
|
|
297
|
+
// Root + manager (seed)
|
|
298
|
+
import WalletManagerEvm from '@tetherto/wdk-wallet-evm'
|
|
299
|
+
import { SeedSignerEvm } from '@tetherto/wdk-wallet-evm/signers'
|
|
300
|
+
const root = new SeedSignerEvm(mnemonic)
|
|
301
|
+
const wallet = new WalletManagerEvm(root, { provider: 'https://...' })
|
|
302
|
+
const account0 = await wallet.getAccount(0)
|
|
303
|
+
|
|
304
|
+
// Single account from a private key
|
|
305
|
+
import { WalletAccountEvm } from '@tetherto/wdk-wallet-evm'
|
|
306
|
+
import { PrivateKeySignerEvm } from '@tetherto/wdk-wallet-evm/signers'
|
|
307
|
+
const signer = new PrivateKeySignerEvm('0x0123...')
|
|
308
|
+
const account = new WalletAccountEvm(signer, { provider: 'https://...' })
|
|
343
309
|
```
|
|
344
310
|
|
|
345
|
-
|
|
346
|
-
- `address` (string): The account's address
|
|
347
|
-
- `config` (object, optional): Configuration object
|
|
348
|
-
- `provider` (string | Eip1193Provider): RPC endpoint URL or EIP-1193 provider instance
|
|
349
|
-
|
|
350
|
-
#### Methods
|
|
351
|
-
|
|
352
|
-
| Method | Description | Returns |
|
|
353
|
-
|--------|-------------|---------|
|
|
354
|
-
| `getBalance()` | Returns the native token balance (in wei) | `Promise<bigint>` |
|
|
355
|
-
| `getTokenBalance(tokenAddress)` | Returns the balance of a specific ERC20 token | `Promise<bigint>` |
|
|
356
|
-
| `quoteSendTransaction(tx)` | Estimates the fee for an EVM transaction | `Promise<{fee: bigint}>` |
|
|
357
|
-
| `quoteTransfer(options)` | Estimates the fee for an ERC20 transfer | `Promise<{fee: bigint}>` |
|
|
358
|
-
|
|
359
|
-
## 🌐 Supported Networks
|
|
311
|
+
## Key Capabilities
|
|
360
312
|
|
|
361
|
-
|
|
313
|
+
- **BIP-39 Seed Phrase Support**: Generate and validate mnemonic seed phrases
|
|
314
|
+
- **BIP-44 Derivation Paths**: Standard Ethereum derivation (m/44'/60')
|
|
315
|
+
- **Multi-Account Management**: Derive multiple accounts from a single seed phrase
|
|
316
|
+
- **EIP-1559 Transaction Support**: Modern fee estimation and transaction sending
|
|
317
|
+
- **ERC-20 Token Support**: Query balances and transfer tokens
|
|
318
|
+
- **Message Signing**: Sign and verify messages (EIP-191 and EIP-712)
|
|
319
|
+
- **Fee Estimation**: Real-time network fee rates with normal/fast tiers
|
|
320
|
+
- **Secure Memory Disposal**: Clear private keys from memory when done
|
|
321
|
+
- **Signer Submodule**: Create your own signer from ISignerEvm, support for Seed and Private key signers
|
|
322
|
+
- **EIP-7702 Delegation**: Delegate EOAs to smart contracts, sign authorizations, and send type 4 transactions
|
|
362
323
|
|
|
363
|
-
|
|
364
|
-
- **Ethereum Testnets** (Sepolia, etc.)
|
|
365
|
-
- **Layer 2 Networks** (Arbitrum, Optimism, etc.)
|
|
366
|
-
- **Other EVM Chains** (Polygon, Avalanche C-Chain, etc.)
|
|
324
|
+
## Compatibility
|
|
367
325
|
|
|
368
|
-
|
|
326
|
+
- **Ethereum Mainnet** and testnets (Sepolia)
|
|
327
|
+
- **Layer 2 Networks**: Arbitrum, Optimism, Base
|
|
328
|
+
- **Other EVM Chains**: Polygon, Avalanche C-Chain, and any EVM-compatible chain
|
|
369
329
|
|
|
370
|
-
|
|
371
|
-
- **Private Key Management**: The package handles private keys internally with memory safety features
|
|
372
|
-
- **Provider Security**: Use trusted RPC endpoints and consider running your own node for production
|
|
373
|
-
- **Transaction Validation**: Always validate transaction details before signing
|
|
374
|
-
- **Memory Cleanup**: Use the `dispose()` method to clear private keys from memory when done
|
|
375
|
-
- **Fee Limits**: Set `transferMaxFee` in config to prevent excessive transaction fees
|
|
376
|
-
- **Gas Estimation**: Always estimate gas before sending transactions
|
|
377
|
-
- **EIP-1559**: Consider using EIP-1559 fee model for better gas price estimation
|
|
378
|
-
- **Contract Interactions**: Verify contract addresses and token decimals before transfers
|
|
330
|
+
## Documentation
|
|
379
331
|
|
|
380
|
-
|
|
332
|
+
| Topic | Description | Link |
|
|
333
|
+
| ------------- | ----------------------------------------- | -------------------------------------------------------------------------------------------------- |
|
|
334
|
+
| Overview | Module overview and feature summary | [Wallet EVM Overview](https://docs.wdk.tether.io/sdk/wallet-modules/wallet-evm) |
|
|
335
|
+
| Usage | End-to-end integration walkthrough | [Wallet EVM Usage](https://docs.wdk.tether.io/sdk/wallet-modules/wallet-evm/usage) |
|
|
336
|
+
| Configuration | Provider, fees, and network configuration | [Wallet EVM Configuration](https://docs.wdk.tether.io/sdk/wallet-modules/wallet-evm/configuration) |
|
|
337
|
+
| API Reference | Complete class and type reference | [Wallet EVM API Reference](https://docs.wdk.tether.io/sdk/wallet-modules/wallet-evm/api-reference) |
|
|
381
338
|
|
|
382
|
-
|
|
339
|
+
## Examples
|
|
383
340
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
npm run lint:fix
|
|
396
|
-
```
|
|
341
|
+
| Example | Description |
|
|
342
|
+
| ------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- |
|
|
343
|
+
| [Create Wallet](https://github.com/tetherto/wdk-examples/blob/main/wallet-evm/create-wallet.ts) | Initialize a wallet manager and derive accounts from a seed phrase |
|
|
344
|
+
| [Manage Accounts](https://github.com/tetherto/wdk-examples/blob/main/wallet-evm/manage-accounts.ts) | Work with multiple accounts and custom derivation paths |
|
|
345
|
+
| [Check Balances](https://github.com/tetherto/wdk-examples/blob/main/wallet-evm/check-balances.ts) | Query native token and ERC-20 balances for owned accounts |
|
|
346
|
+
| [Read-Only Account](https://github.com/tetherto/wdk-examples/blob/main/wallet-evm/read-only-account.ts) | Monitor balances for any address without a private key |
|
|
347
|
+
| [Send Transaction](https://github.com/tetherto/wdk-examples/blob/main/wallet-evm/send-transaction.ts) | Estimate fees and send native token transactions (EIP-1559 + legacy) |
|
|
348
|
+
| [Token Transfer](https://github.com/tetherto/wdk-examples/blob/main/wallet-evm/token-transfer.ts) | Transfer ERC-20 tokens and estimate transfer fees |
|
|
349
|
+
| [Sign & Verify Message](https://github.com/tetherto/wdk-examples/blob/main/wallet-evm/sign-verify-message.ts) | Sign messages and verify signatures |
|
|
350
|
+
| [Fee Management](https://github.com/tetherto/wdk-examples/blob/main/wallet-evm/fee-management.ts) | Retrieve current network fee rates |
|
|
351
|
+
| [Memory Management](https://github.com/tetherto/wdk-examples/blob/main/wallet-evm/memory-management.ts) | Securely dispose wallets and clear private keys from memory |
|
|
397
352
|
|
|
398
|
-
|
|
353
|
+
> For detailed walkthroughs, see the [Usage Guide](https://docs.wdk.tether.io/sdk/wallet-modules/wallet-evm/usage).
|
|
354
|
+
> See all runnable examples in the [wdk-examples](https://github.com/tetherto/wdk-examples) repository.
|
|
399
355
|
|
|
400
|
-
|
|
401
|
-
# Run tests
|
|
402
|
-
npm test
|
|
356
|
+
## Community
|
|
403
357
|
|
|
404
|
-
|
|
405
|
-
npm run test:coverage
|
|
406
|
-
```
|
|
358
|
+
Join the [WDK Discord](https://discord.gg/arYXDhHB2w) to connect with other developers.
|
|
407
359
|
|
|
408
|
-
##
|
|
360
|
+
## Support
|
|
409
361
|
|
|
410
|
-
|
|
362
|
+
For support, please [open an issue](https://github.com/tetherto/wdk-wallet-evm/issues) on GitHub or reach out via [email](mailto:wallet-info@tether.io).
|
|
411
363
|
|
|
412
|
-
##
|
|
364
|
+
## Contributing
|
|
413
365
|
|
|
414
366
|
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
415
367
|
|
|
416
|
-
##
|
|
368
|
+
## License
|
|
417
369
|
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
---
|
|
370
|
+
This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.
|
package/bare.js
CHANGED
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
'use strict'
|
|
15
15
|
|
|
16
|
-
import 'bare-
|
|
16
|
+
import 'bare-node-runtime/global'
|
|
17
17
|
|
|
18
|
-
export * from './index.js' with { imports: 'bare-
|
|
18
|
+
export * from './index.js' with { imports: 'bare-node-runtime/imports' }
|
|
19
19
|
|
|
20
|
-
export { default } from './index.js' with { imports: 'bare-
|
|
20
|
+
export { default } from './index.js' with { imports: 'bare-node-runtime/imports' }
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
require('@nomicfoundation/hardhat-ethers')
|
|
2
|
-
|
|
3
1
|
/** @type {import('hardhat/config').HardhatUserConfig} */
|
|
4
|
-
|
|
2
|
+
export default {
|
|
5
3
|
networks: {
|
|
6
4
|
hardhat: {
|
|
5
|
+
type: 'edr-simulated',
|
|
6
|
+
chainId: 1,
|
|
7
|
+
hardfork: 'prague',
|
|
7
8
|
accounts: {
|
|
8
9
|
mnemonic: 'anger burst story spy face pattern whale quit delay fiction ball solve',
|
|
9
10
|
path: "m/44'/60'/0'/0",
|