@mcp-dockmaster/mcp-cryptowallet-evm 1.0.1 → 1.0.3
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/build/handlers/utils.d.ts +1 -1
- package/build/handlers/utils.js +9 -0
- package/build/handlers/utils.js.map +1 -1
- package/build/handlers/wallet.d.ts +3 -2
- package/build/handlers/wallet.js +158 -93
- package/build/handlers/wallet.js.map +1 -1
- package/build/handlers/wallet.types.d.ts +14 -0
- package/build/handlers/wallet.types.js +2 -0
- package/build/handlers/wallet.types.js.map +1 -0
- package/build/index.js +0 -0
- package/build/tools.d.ts +67 -3
- package/build/tools.js +42 -41
- package/build/tools.js.map +1 -1
- package/package.json +1 -1
- package/.eslintrc/index.js +0 -12
- package/required-methods.md +0 -53
- package/tests/handlers/network.test.ts +0 -73
- package/tests/handlers/provider.test.ts +0 -197
- package/tests/handlers/wallet.test.ts +0 -289
@@ -26,4 +26,4 @@ export declare const getProvider: (providerUrl?: string) => ethers.providers.Pro
|
|
26
26
|
* @param provider Optional provider to connect the wallet to
|
27
27
|
* @returns An ethers.js wallet
|
28
28
|
*/
|
29
|
-
export declare const getWallet: (walletData
|
29
|
+
export declare const getWallet: (walletData?: string, password?: string, providerUrl?: string) => Promise<ethers.Wallet>;
|
package/build/handlers/utils.js
CHANGED
@@ -60,6 +60,15 @@ export const getProvider = (providerUrl) => {
|
|
60
60
|
*/
|
61
61
|
export const getWallet = async (walletData, password, providerUrl) => {
|
62
62
|
const provider = providerUrl ? getProvider(providerUrl) : undefined;
|
63
|
+
// If walletData is not provided, check for PRIVATE_KEY environment variable
|
64
|
+
if (!walletData && process.env.PRIVATE_KEY) {
|
65
|
+
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY);
|
66
|
+
return provider ? wallet.connect(provider) : wallet;
|
67
|
+
}
|
68
|
+
// If no walletData and no environment variable, throw an error
|
69
|
+
if (!walletData) {
|
70
|
+
throw new Error("Wallet data is required or set PRIVATE_KEY environment variable");
|
71
|
+
}
|
63
72
|
try {
|
64
73
|
// Try to parse as JSON first
|
65
74
|
if (walletData.startsWith("{")) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/handlers/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAI,MAAS,EAAE,OAAgB,EAAuB,EAAE;IAC3F,OAAO;QACL,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,OAAO,IAAI,kCAAkC;aACpD;SACF;QACD,OAAO,EAAE,KAAK;QACd,UAAU,EAAE,MAAM;KACnB,CAAC;AACJ,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,OAAe,EAAyB,EAAE;IAC5E,OAAO;QACL,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,OAAO;aACd;SACF;QACD,OAAO,EAAE,IAAI;QACb,UAAU,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE;KAC/B,CAAC;AACJ,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,WAAoB,EAA6B,EAAE;IAC7E,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,8DAA8D;QAC9D,OAAO,MAAM,CAAC,kBAAkB,EAAE,CAAC;IACrC,CAAC;IAED,IAAI,CAAC;QACH,OAAO,IAAI,MAAM,CAAC,SAAS,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;IAC3D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,yBAAyB,WAAW,EAAE,CAAC,CAAC;IAC1D,CAAC;AACH,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAA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C;YACtD,OAAO,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QACtD,CAAC;QAED,4BAA4B;QAC5B,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAC7C,OAAO,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IACtD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,wBAAyB,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC;IACtE,CAAC;AACH,CAAC,CAAC"}
|
@@ -1,13 +1,14 @@
|
|
1
1
|
import { ToolResultSchema } from "../types.js";
|
2
|
+
import { fromPrivateKeyHandlerInput, createMnemonicPhraseHandlerInput } from "./wallet.types.js";
|
2
3
|
export declare const createWalletHandler: (input: any) => Promise<ToolResultSchema<any>>;
|
3
|
-
export declare const fromPrivateKeyHandler: (input:
|
4
|
+
export declare const fromPrivateKeyHandler: (input: fromPrivateKeyHandlerInput) => Promise<ToolResultSchema<any>>;
|
5
|
+
export declare const createMnemonicPhraseHandler: (input: createMnemonicPhraseHandlerInput) => Promise<ToolResultSchema<any>>;
|
4
6
|
export declare const fromMnemonicHandler: (input: any) => Promise<ToolResultSchema<any>>;
|
5
7
|
export declare const fromEncryptedJsonHandler: (input: any) => Promise<ToolResultSchema<any>>;
|
6
8
|
export declare const encryptWalletHandler: (input: any) => Promise<ToolResultSchema<any>>;
|
7
9
|
export declare const getAddressHandler: (input: any) => Promise<ToolResultSchema<any>>;
|
8
10
|
export declare const getPublicKeyHandler: (input: any) => Promise<ToolResultSchema<any>>;
|
9
11
|
export declare const getPrivateKeyHandler: (input: any) => Promise<ToolResultSchema<any>>;
|
10
|
-
export declare const getMnemonicHandler: (input: any) => Promise<ToolResultSchema<any>>;
|
11
12
|
export declare const getBalanceHandler: (input: any) => Promise<ToolResultSchema<any>>;
|
12
13
|
export declare const getChainIdHandler: (input: any) => Promise<ToolResultSchema<any>>;
|
13
14
|
export declare const getGasPriceHandler: (input: any) => Promise<ToolResultSchema<any>>;
|
package/build/handlers/wallet.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import { ethers } from "ethers";
|
2
2
|
import { createSuccessResponse, createErrorResponse, getProvider, getWallet } from "./utils.js";
|
3
|
+
import { generateMnemonic, } from '@scure/bip39';
|
3
4
|
// Wallet Creation and Management
|
4
5
|
export const createWalletHandler = async (input) => {
|
5
6
|
try {
|
@@ -22,7 +23,13 @@ export const createWalletHandler = async (input) => {
|
|
22
23
|
const encryptedWallet = await wallet.encrypt(input.password);
|
23
24
|
result.encryptedWallet = encryptedWallet;
|
24
25
|
}
|
25
|
-
return createSuccessResponse(result,
|
26
|
+
return createSuccessResponse(result, `Wallet created successfully:
|
27
|
+
Address: ${wallet.address}
|
28
|
+
Private Key: ${wallet.privateKey}
|
29
|
+
Public Key: ${wallet.publicKey}
|
30
|
+
Mnemonic: ${wallet.mnemonic?.phrase}
|
31
|
+
Encrypted Wallet: ${result.encryptedWallet ? "Yes" : "No"}
|
32
|
+
`);
|
26
33
|
}
|
27
34
|
catch (error) {
|
28
35
|
return createErrorResponse(`Failed to create wallet: ${error.message}`);
|
@@ -39,35 +46,58 @@ export const fromPrivateKeyHandler = async (input) => {
|
|
39
46
|
address: wallet.address,
|
40
47
|
privateKey: wallet.privateKey,
|
41
48
|
publicKey: wallet.publicKey
|
42
|
-
},
|
49
|
+
}, `Wallet created from private key successfully:
|
50
|
+
Address: ${wallet.address}
|
51
|
+
Private Key: ${wallet.privateKey}
|
52
|
+
Public Key: ${wallet.publicKey}
|
53
|
+
`);
|
43
54
|
}
|
44
55
|
catch (error) {
|
45
56
|
return createErrorResponse(`Failed to create wallet from private key: ${error.message}`);
|
46
57
|
}
|
47
58
|
};
|
59
|
+
export const createMnemonicPhraseHandler = async (input) => {
|
60
|
+
try {
|
61
|
+
const { wordlist } = await import(`@scure/bip39/wordlists/${input.locale || 'english'}`);
|
62
|
+
if (!wordlist) {
|
63
|
+
return createErrorResponse("Invalid locale");
|
64
|
+
}
|
65
|
+
// Convert length to entropy bits (12 words = 128 bits, 15 words = 160 bits, etc)
|
66
|
+
const entropyBits = ((input.length ?? 12) / 3) * 32;
|
67
|
+
const mnemonic = generateMnemonic(wordlist, entropyBits);
|
68
|
+
return createSuccessResponse({
|
69
|
+
mnemonic: mnemonic
|
70
|
+
}, `Mnemonic phrase created successfully:
|
71
|
+
Mnemonic: "${mnemonic}"
|
72
|
+
`);
|
73
|
+
}
|
74
|
+
catch (error) {
|
75
|
+
return createErrorResponse(`Failed to create mnemonic phrase: ${error.message}`);
|
76
|
+
}
|
77
|
+
};
|
48
78
|
export const fromMnemonicHandler = async (input) => {
|
49
79
|
try {
|
50
80
|
if (!input.mnemonic) {
|
51
81
|
return createErrorResponse("Mnemonic is required");
|
52
82
|
}
|
53
|
-
const options = {
|
54
|
-
|
55
|
-
|
56
|
-
}
|
57
|
-
if (input.locale) {
|
58
|
-
options.wordlist = ethers.wordlists[input.locale] || ethers.wordlists.en;
|
59
|
-
}
|
83
|
+
const options = {
|
84
|
+
path: input.path,
|
85
|
+
wordlist: (input.locale && ethers.wordlists[input.locale]) || ethers.wordlists.en
|
86
|
+
};
|
60
87
|
const provider = input.provider ? getProvider(input.provider) : undefined;
|
61
88
|
const wallet = ethers.Wallet.fromMnemonic(input.mnemonic, options.path, options.wordlist);
|
62
|
-
if (provider)
|
89
|
+
if (provider)
|
63
90
|
wallet.connect(provider);
|
64
|
-
}
|
65
91
|
return createSuccessResponse({
|
66
92
|
address: wallet.address,
|
67
93
|
mnemonic: wallet.mnemonic?.phrase,
|
68
94
|
privateKey: wallet.privateKey,
|
69
95
|
publicKey: wallet.publicKey
|
70
|
-
},
|
96
|
+
}, `Wallet created from mnemonic successfully:
|
97
|
+
Address: ${wallet.address}
|
98
|
+
Private Key: ${wallet.privateKey}
|
99
|
+
Public Key: ${wallet.publicKey}
|
100
|
+
`);
|
71
101
|
}
|
72
102
|
catch (error) {
|
73
103
|
return createErrorResponse(`Failed to create wallet from mnemonic: ${error.message}`);
|
@@ -117,9 +147,6 @@ export const encryptWalletHandler = async (input) => {
|
|
117
147
|
// Wallet Properties
|
118
148
|
export const getAddressHandler = async (input) => {
|
119
149
|
try {
|
120
|
-
if (!input.wallet) {
|
121
|
-
return createErrorResponse("Wallet is required");
|
122
|
-
}
|
123
150
|
const wallet = await getWallet(input.wallet);
|
124
151
|
return createSuccessResponse({
|
125
152
|
address: wallet.address
|
@@ -131,9 +158,6 @@ export const getAddressHandler = async (input) => {
|
|
131
158
|
};
|
132
159
|
export const getPublicKeyHandler = async (input) => {
|
133
160
|
try {
|
134
|
-
if (!input.wallet) {
|
135
|
-
return createErrorResponse("Wallet is required");
|
136
|
-
}
|
137
161
|
const wallet = await getWallet(input.wallet);
|
138
162
|
return createSuccessResponse({
|
139
163
|
publicKey: wallet.publicKey
|
@@ -145,9 +169,6 @@ export const getPublicKeyHandler = async (input) => {
|
|
145
169
|
};
|
146
170
|
export const getPrivateKeyHandler = async (input) => {
|
147
171
|
try {
|
148
|
-
if (!input.wallet) {
|
149
|
-
return createErrorResponse("Wallet is required");
|
150
|
-
}
|
151
172
|
const wallet = await getWallet(input.wallet, input.password);
|
152
173
|
return createSuccessResponse({
|
153
174
|
privateKey: wallet.privateKey
|
@@ -157,38 +178,21 @@ export const getPrivateKeyHandler = async (input) => {
|
|
157
178
|
return createErrorResponse(`Failed to get wallet private key: ${error.message}`);
|
158
179
|
}
|
159
180
|
};
|
160
|
-
export const getMnemonicHandler = async (input) => {
|
161
|
-
try {
|
162
|
-
if (!input.wallet) {
|
163
|
-
return createErrorResponse("Wallet is required");
|
164
|
-
}
|
165
|
-
const wallet = await getWallet(input.wallet, input.password);
|
166
|
-
if (!wallet.mnemonic) {
|
167
|
-
return createErrorResponse("This wallet does not have a mnemonic phrase");
|
168
|
-
}
|
169
|
-
return createSuccessResponse({
|
170
|
-
mnemonic: wallet.mnemonic.phrase
|
171
|
-
}, "WARNING: Never share your mnemonic phrase with anyone. Wallet mnemonic retrieved successfully");
|
172
|
-
}
|
173
|
-
catch (error) {
|
174
|
-
return createErrorResponse(`Failed to get wallet mnemonic: ${error.message}`);
|
175
|
-
}
|
176
|
-
};
|
177
181
|
// Blockchain Methods
|
178
182
|
export const getBalanceHandler = async (input) => {
|
179
183
|
try {
|
180
|
-
if (!input.
|
181
|
-
return createErrorResponse("
|
184
|
+
if (!input.provider) {
|
185
|
+
return createErrorResponse("Provider URL is required to get balance");
|
182
186
|
}
|
183
187
|
const wallet = await getWallet(input.wallet, input.password, input.provider);
|
184
|
-
|
185
|
-
return createErrorResponse("Provider is required to get balance");
|
186
|
-
}
|
187
|
-
const balance = await wallet.getBalance(input.blockTag);
|
188
|
+
const balance = await wallet.getBalance(input.blockTag ?? "latest");
|
188
189
|
return createSuccessResponse({
|
189
190
|
balance: balance.toString(),
|
190
191
|
balanceInEth: ethers.utils.formatEther(balance)
|
191
|
-
},
|
192
|
+
}, `Wallet balance retrieved successfully
|
193
|
+
Balance: ${balance.toString()}
|
194
|
+
Balance in ETH: ${ethers.utils.formatEther(balance)}
|
195
|
+
`);
|
192
196
|
}
|
193
197
|
catch (error) {
|
194
198
|
return createErrorResponse(`Failed to get wallet balance: ${error.message}`);
|
@@ -196,9 +200,6 @@ export const getBalanceHandler = async (input) => {
|
|
196
200
|
};
|
197
201
|
export const getChainIdHandler = async (input) => {
|
198
202
|
try {
|
199
|
-
if (!input.wallet) {
|
200
|
-
return createErrorResponse("Wallet is required");
|
201
|
-
}
|
202
203
|
const wallet = await getWallet(input.wallet, input.password, input.provider);
|
203
204
|
if (!wallet.provider) {
|
204
205
|
return createErrorResponse("Provider is required to get chain ID");
|
@@ -206,7 +207,9 @@ export const getChainIdHandler = async (input) => {
|
|
206
207
|
const chainId = await wallet.getChainId();
|
207
208
|
return createSuccessResponse({
|
208
209
|
chainId
|
209
|
-
},
|
210
|
+
}, `Chain ID retrieved successfully
|
211
|
+
Chain ID: ${chainId.toString()}
|
212
|
+
`);
|
210
213
|
}
|
211
214
|
catch (error) {
|
212
215
|
return createErrorResponse(`Failed to get chain ID: ${error.message}`);
|
@@ -214,9 +217,6 @@ export const getChainIdHandler = async (input) => {
|
|
214
217
|
};
|
215
218
|
export const getGasPriceHandler = async (input) => {
|
216
219
|
try {
|
217
|
-
if (!input.wallet) {
|
218
|
-
return createErrorResponse("Wallet is required");
|
219
|
-
}
|
220
220
|
const wallet = await getWallet(input.wallet, input.password, input.provider);
|
221
221
|
if (!wallet.provider) {
|
222
222
|
return createErrorResponse("Provider is required to get gas price");
|
@@ -225,7 +225,10 @@ export const getGasPriceHandler = async (input) => {
|
|
225
225
|
return createSuccessResponse({
|
226
226
|
gasPrice: gasPrice.toString(),
|
227
227
|
gasPriceInGwei: ethers.utils.formatUnits(gasPrice, "gwei")
|
228
|
-
},
|
228
|
+
}, `Gas price retrieved successfully
|
229
|
+
Gas price: ${gasPrice.toString()}
|
230
|
+
Gas price in Gwei: ${ethers.utils.formatUnits(gasPrice, "gwei")}
|
231
|
+
`);
|
229
232
|
}
|
230
233
|
catch (error) {
|
231
234
|
return createErrorResponse(`Failed to get gas price: ${error.message}`);
|
@@ -233,9 +236,6 @@ export const getGasPriceHandler = async (input) => {
|
|
233
236
|
};
|
234
237
|
export const getTransactionCountHandler = async (input) => {
|
235
238
|
try {
|
236
|
-
if (!input.wallet) {
|
237
|
-
return createErrorResponse("Wallet is required");
|
238
|
-
}
|
239
239
|
const wallet = await getWallet(input.wallet, input.password, input.provider);
|
240
240
|
if (!wallet.provider) {
|
241
241
|
return createErrorResponse("Provider is required to get transaction count");
|
@@ -243,7 +243,9 @@ export const getTransactionCountHandler = async (input) => {
|
|
243
243
|
const transactionCount = await wallet.getTransactionCount(input.blockTag);
|
244
244
|
return createSuccessResponse({
|
245
245
|
transactionCount
|
246
|
-
},
|
246
|
+
}, `Transaction count retrieved successfully
|
247
|
+
Transaction count: ${transactionCount.toString()}
|
248
|
+
`);
|
247
249
|
}
|
248
250
|
catch (error) {
|
249
251
|
return createErrorResponse(`Failed to get transaction count: ${error.message}`);
|
@@ -251,9 +253,6 @@ export const getTransactionCountHandler = async (input) => {
|
|
251
253
|
};
|
252
254
|
export const callHandler = async (input) => {
|
253
255
|
try {
|
254
|
-
if (!input.wallet) {
|
255
|
-
return createErrorResponse("Wallet is required");
|
256
|
-
}
|
257
256
|
if (!input.transaction) {
|
258
257
|
return createErrorResponse("Transaction is required");
|
259
258
|
}
|
@@ -264,7 +263,9 @@ export const callHandler = async (input) => {
|
|
264
263
|
const result = await wallet.call(input.transaction, input.blockTag);
|
265
264
|
return createSuccessResponse({
|
266
265
|
result
|
267
|
-
},
|
266
|
+
}, `Contract call executed successfully
|
267
|
+
Result: ${result}
|
268
|
+
`);
|
268
269
|
}
|
269
270
|
catch (error) {
|
270
271
|
return createErrorResponse(`Failed to call contract: ${error.message}`);
|
@@ -273,9 +274,6 @@ export const callHandler = async (input) => {
|
|
273
274
|
// Transaction Methods
|
274
275
|
export const sendTransactionHandler = async (input) => {
|
275
276
|
try {
|
276
|
-
if (!input.wallet) {
|
277
|
-
return createErrorResponse("Wallet is required");
|
278
|
-
}
|
279
277
|
if (!input.transaction) {
|
280
278
|
return createErrorResponse("Transaction is required");
|
281
279
|
}
|
@@ -295,7 +293,13 @@ export const sendTransactionHandler = async (input) => {
|
|
295
293
|
from: tx.from,
|
296
294
|
to: tx.to,
|
297
295
|
type: tx.type
|
298
|
-
},
|
296
|
+
}, `Transaction sent successfully
|
297
|
+
Hash: ${tx.hash}
|
298
|
+
Nonce: ${tx.nonce.toString()}
|
299
|
+
Gas limit: ${tx.gasLimit.toString()}
|
300
|
+
Gas price: ${tx.gasPrice?.toString()}
|
301
|
+
Data: ${tx.data}
|
302
|
+
`);
|
299
303
|
}
|
300
304
|
catch (error) {
|
301
305
|
return createErrorResponse(`Failed to send transaction: ${error.message}`);
|
@@ -303,9 +307,6 @@ export const sendTransactionHandler = async (input) => {
|
|
303
307
|
};
|
304
308
|
export const signTransactionHandler = async (input) => {
|
305
309
|
try {
|
306
|
-
if (!input.wallet) {
|
307
|
-
return createErrorResponse("Wallet is required");
|
308
|
-
}
|
309
310
|
if (!input.transaction) {
|
310
311
|
return createErrorResponse("Transaction is required");
|
311
312
|
}
|
@@ -315,7 +316,9 @@ export const signTransactionHandler = async (input) => {
|
|
315
316
|
const signedTx = await wallet.signTransaction(populatedTx);
|
316
317
|
return createSuccessResponse({
|
317
318
|
signedTransaction: signedTx
|
318
|
-
},
|
319
|
+
}, `Transaction signed successfully
|
320
|
+
Signed transaction: ${signedTx}
|
321
|
+
`);
|
319
322
|
}
|
320
323
|
catch (error) {
|
321
324
|
return createErrorResponse(`Failed to sign transaction: ${error.message}`);
|
@@ -323,9 +326,6 @@ export const signTransactionHandler = async (input) => {
|
|
323
326
|
};
|
324
327
|
export const populateTransactionHandler = async (input) => {
|
325
328
|
try {
|
326
|
-
if (!input.wallet) {
|
327
|
-
return createErrorResponse("Wallet is required");
|
328
|
-
}
|
329
329
|
if (!input.transaction) {
|
330
330
|
return createErrorResponse("Transaction is required");
|
331
331
|
}
|
@@ -348,7 +348,13 @@ export const populateTransactionHandler = async (input) => {
|
|
348
348
|
maxFeePerGas: populatedTx.maxFeePerGas?.toString(),
|
349
349
|
maxPriorityFeePerGas: populatedTx.maxPriorityFeePerGas?.toString()
|
350
350
|
}
|
351
|
-
},
|
351
|
+
}, `Transaction populated successfully
|
352
|
+
To: ${populatedTx.to}
|
353
|
+
From: ${populatedTx.from}
|
354
|
+
Nonce: ${populatedTx.nonce?.toString() ?? "Not specified"}
|
355
|
+
Gas limit: ${populatedTx.gasLimit?.toString() ?? "Not specified"}
|
356
|
+
Gas price: ${populatedTx.gasPrice?.toString() ?? "Not specified"}
|
357
|
+
`);
|
352
358
|
}
|
353
359
|
catch (error) {
|
354
360
|
return createErrorResponse(`Failed to populate transaction: ${error.message}`);
|
@@ -357,9 +363,6 @@ export const populateTransactionHandler = async (input) => {
|
|
357
363
|
// Signing Methods
|
358
364
|
export const signMessageHandler = async (input) => {
|
359
365
|
try {
|
360
|
-
if (!input.wallet) {
|
361
|
-
return createErrorResponse("Wallet is required");
|
362
|
-
}
|
363
366
|
if (!input.message) {
|
364
367
|
return createErrorResponse("Message is required");
|
365
368
|
}
|
@@ -368,7 +371,10 @@ export const signMessageHandler = async (input) => {
|
|
368
371
|
return createSuccessResponse({
|
369
372
|
signature,
|
370
373
|
message: input.message
|
371
|
-
},
|
374
|
+
}, `Message signed successfully
|
375
|
+
Signature: ${signature}
|
376
|
+
Message: "${input.message}"
|
377
|
+
`);
|
372
378
|
}
|
373
379
|
catch (error) {
|
374
380
|
return createErrorResponse(`Failed to sign message: ${error.message}`);
|
@@ -391,7 +397,12 @@ export const signTypedDataHandler = async (input) => {
|
|
391
397
|
domain: input.domain,
|
392
398
|
types: input.types,
|
393
399
|
value: input.value
|
394
|
-
},
|
400
|
+
}, `Typed data signed successfully
|
401
|
+
Signature: ${signature}
|
402
|
+
Domain: ${input.domain}
|
403
|
+
Types: ${input.types}
|
404
|
+
Value: ${input.value}
|
405
|
+
`);
|
395
406
|
}
|
396
407
|
catch (error) {
|
397
408
|
return createErrorResponse(`Failed to sign typed data: ${error.message}`);
|
@@ -407,7 +418,15 @@ export const verifyMessageHandler = async (input) => {
|
|
407
418
|
return createSuccessResponse({
|
408
419
|
isValid,
|
409
420
|
recoveredAddress
|
410
|
-
}, isValid ?
|
421
|
+
}, isValid ? `Signature verified successfully
|
422
|
+
Message: "${input.message}"
|
423
|
+
Signature: ${input.signature}
|
424
|
+
Address: ${input.address}
|
425
|
+
` : `Signature verification failed
|
426
|
+
Message: "${input.message}"
|
427
|
+
Signature: ${input.signature}
|
428
|
+
Address: ${input.address}
|
429
|
+
`);
|
411
430
|
}
|
412
431
|
catch (error) {
|
413
432
|
return createErrorResponse(`Failed to verify message: ${error.message}`);
|
@@ -424,7 +443,13 @@ export const verifyTypedDataHandler = async (input) => {
|
|
424
443
|
return createSuccessResponse({
|
425
444
|
isValid,
|
426
445
|
recoveredAddress
|
427
|
-
}, isValid ?
|
446
|
+
}, isValid ? `Typed data signature is valid
|
447
|
+
Domain: ${input.domain}
|
448
|
+
Types: ${input.types}
|
449
|
+
Value: ${input.value}
|
450
|
+
Signature: ${input.signature}
|
451
|
+
Address: ${input.address}
|
452
|
+
` : "Typed data signature is invalid");
|
428
453
|
}
|
429
454
|
catch (error) {
|
430
455
|
return createErrorResponse(`Failed to verify typed data: ${error.message}`);
|
@@ -445,7 +470,12 @@ export const getBlockHandler = async (input) => {
|
|
445
470
|
const block = await provider.getBlock(input.blockHashOrBlockTag, input.includeTransactions);
|
446
471
|
return createSuccessResponse({
|
447
472
|
block
|
448
|
-
},
|
473
|
+
}, `Block retrieved successfully
|
474
|
+
Block hash: ${block.hash}
|
475
|
+
Block number: ${block.number?.toString() ?? "Not specified"}
|
476
|
+
Block timestamp: ${block.timestamp?.toString() ?? "Not specified"}
|
477
|
+
Block transactions: ${block.transactions?.length ?? "Not specified"}
|
478
|
+
`);
|
449
479
|
}
|
450
480
|
catch (error) {
|
451
481
|
return createErrorResponse(`Failed to get block: ${error.message}`);
|
@@ -463,7 +493,10 @@ export const getTransactionHandler = async (input) => {
|
|
463
493
|
const transaction = await provider.getTransaction(input.transactionHash);
|
464
494
|
return createSuccessResponse({
|
465
495
|
transaction
|
466
|
-
},
|
496
|
+
}, `Transaction retrieved successfully
|
497
|
+
Transaction hash: ${input.transactionHash}
|
498
|
+
Transaction: ${transaction}
|
499
|
+
`);
|
467
500
|
}
|
468
501
|
catch (error) {
|
469
502
|
return createErrorResponse(`Failed to get transaction: ${error.message}`);
|
@@ -481,7 +514,10 @@ export const getTransactionReceiptHandler = async (input) => {
|
|
481
514
|
const receipt = await provider.getTransactionReceipt(input.transactionHash);
|
482
515
|
return createSuccessResponse({
|
483
516
|
receipt
|
484
|
-
},
|
517
|
+
}, `Transaction receipt retrieved successfully
|
518
|
+
Transaction hash: ${input.transactionHash}
|
519
|
+
Transaction receipt: ${receipt}
|
520
|
+
`);
|
485
521
|
}
|
486
522
|
catch (error) {
|
487
523
|
return createErrorResponse(`Failed to get transaction receipt: ${error.message}`);
|
@@ -499,7 +535,10 @@ export const getCodeHandler = async (input) => {
|
|
499
535
|
const code = await provider.getCode(input.address, input.blockTag);
|
500
536
|
return createSuccessResponse({
|
501
537
|
code
|
502
|
-
},
|
538
|
+
}, `Code retrieved successfully
|
539
|
+
Address: ${input.address}
|
540
|
+
Code: ${code}
|
541
|
+
`);
|
503
542
|
}
|
504
543
|
catch (error) {
|
505
544
|
return createErrorResponse(`Failed to get code: ${error.message}`);
|
@@ -520,7 +559,11 @@ export const getStorageAtHandler = async (input) => {
|
|
520
559
|
const storage = await provider.getStorageAt(input.address, input.position, input.blockTag);
|
521
560
|
return createSuccessResponse({
|
522
561
|
storage
|
523
|
-
},
|
562
|
+
}, `Storage retrieved successfully
|
563
|
+
Address: ${input.address}
|
564
|
+
Position: ${input.position}
|
565
|
+
Storage: ${storage}
|
566
|
+
`);
|
524
567
|
}
|
525
568
|
catch (error) {
|
526
569
|
return createErrorResponse(`Failed to get storage: ${error.message}`);
|
@@ -538,7 +581,9 @@ export const estimateGasHandler = async (input) => {
|
|
538
581
|
const gasEstimate = await provider.estimateGas(input.transaction);
|
539
582
|
return createSuccessResponse({
|
540
583
|
gasEstimate: gasEstimate.toString()
|
541
|
-
},
|
584
|
+
}, `Gas estimate retrieved successfully
|
585
|
+
Gas estimate: ${gasEstimate.toString()}
|
586
|
+
`);
|
542
587
|
}
|
543
588
|
catch (error) {
|
544
589
|
return createErrorResponse(`Failed to estimate gas: ${error.message}`);
|
@@ -556,7 +601,9 @@ export const getLogsHandler = async (input) => {
|
|
556
601
|
const logs = await provider.getLogs(input.filter);
|
557
602
|
return createSuccessResponse({
|
558
603
|
logs
|
559
|
-
},
|
604
|
+
}, `Logs retrieved successfully
|
605
|
+
Logs: ${logs}
|
606
|
+
`);
|
560
607
|
}
|
561
608
|
catch (error) {
|
562
609
|
return createErrorResponse(`Failed to get logs: ${error.message}`);
|
@@ -579,7 +626,10 @@ export const getEnsResolverHandler = async (input) => {
|
|
579
626
|
address: resolver.address,
|
580
627
|
name: resolver.name
|
581
628
|
} : null
|
582
|
-
}, resolver ?
|
629
|
+
}, resolver ? `ENS resolver retrieved successfully
|
630
|
+
Address: ${resolver.address}
|
631
|
+
Name: ${resolver.name}
|
632
|
+
` : "No resolver found for this ENS name");
|
583
633
|
}
|
584
634
|
catch (error) {
|
585
635
|
return createErrorResponse(`Failed to get ENS resolver: ${error.message}`);
|
@@ -597,7 +647,9 @@ export const lookupAddressHandler = async (input) => {
|
|
597
647
|
const name = await provider.lookupAddress(input.address);
|
598
648
|
return createSuccessResponse({
|
599
649
|
name
|
600
|
-
}, name ?
|
650
|
+
}, name ? `ENS name retrieved successfully
|
651
|
+
Name: ${name}
|
652
|
+
` : "No ENS name found for this address");
|
601
653
|
}
|
602
654
|
catch (error) {
|
603
655
|
return createErrorResponse(`Failed to lookup ENS name: ${error.message}`);
|
@@ -615,7 +667,10 @@ export const resolveNameHandler = async (input) => {
|
|
615
667
|
const address = await provider.resolveName(input.name);
|
616
668
|
return createSuccessResponse({
|
617
669
|
address
|
618
|
-
}, address ?
|
670
|
+
}, address ? `ENS name resolved successfully
|
671
|
+
Name: ${input.name}
|
672
|
+
Address: ${address}
|
673
|
+
` : "Could not resolve this ENS name");
|
619
674
|
}
|
620
675
|
catch (error) {
|
621
676
|
return createErrorResponse(`Failed to resolve ENS name: ${error.message}`);
|
@@ -635,7 +690,11 @@ export const getNetworkHandler = async (input) => {
|
|
635
690
|
chainId: network.chainId,
|
636
691
|
ensAddress: network.ensAddress
|
637
692
|
}
|
638
|
-
},
|
693
|
+
}, `Network information retrieved successfully
|
694
|
+
Network name: ${network.name}
|
695
|
+
Chain ID: ${network.chainId}
|
696
|
+
ENS address: ${network.ensAddress}
|
697
|
+
`);
|
639
698
|
}
|
640
699
|
catch (error) {
|
641
700
|
return createErrorResponse(`Failed to get network information: ${error.message}`);
|
@@ -650,7 +709,9 @@ export const getBlockNumberHandler = async (input) => {
|
|
650
709
|
const blockNumber = await provider.getBlockNumber();
|
651
710
|
return createSuccessResponse({
|
652
711
|
blockNumber
|
653
|
-
},
|
712
|
+
}, `Block number retrieved successfully
|
713
|
+
Block number: ${blockNumber.toString()}
|
714
|
+
`);
|
654
715
|
}
|
655
716
|
catch (error) {
|
656
717
|
return createErrorResponse(`Failed to get block number: ${error.message}`);
|
@@ -671,7 +732,11 @@ export const getFeeDataHandler = async (input) => {
|
|
671
732
|
maxFeePerGas: feeData.maxFeePerGas?.toString(),
|
672
733
|
maxPriorityFeePerGas: feeData.maxPriorityFeePerGas?.toString()
|
673
734
|
}
|
674
|
-
},
|
735
|
+
}, `Fee data retrieved successfully
|
736
|
+
Gas price: ${feeData.gasPrice?.toString()}
|
737
|
+
Max fee per gas: ${feeData.maxFeePerGas?.toString()}
|
738
|
+
Max priority fee per gas: ${feeData.maxPriorityFeePerGas?.toString()}
|
739
|
+
`);
|
675
740
|
}
|
676
741
|
catch (error) {
|
677
742
|
return createErrorResponse(`Failed to get fee data: ${error.message}`);
|