@mcp-dockmaster/mcp-cryptowallet-evm 1.0.3 → 1.0.5
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 +4 -4
- package/build/handlers/utils.js +20 -10
- package/build/handlers/utils.js.map +1 -1
- package/build/handlers/wallet.d.ts +1 -0
- package/build/handlers/wallet.js +73 -73
- package/build/handlers/wallet.js.map +1 -1
- package/build/tools.d.ts +61 -109
- package/build/tools.js +36 -50
- package/build/tools.js.map +1 -1
- package/package.json +1 -1
- package/src/handlers/utils.ts +21 -12
- package/src/handlers/wallet.ts +77 -91
- package/src/tools.ts +37 -50
package/src/handlers/wallet.ts
CHANGED
@@ -1,10 +1,24 @@
|
|
1
|
-
import { ethers } from "ethers";
|
1
|
+
import { ethers, providers } from "ethers";
|
2
2
|
import { ToolResultSchema } from "../types.js";
|
3
|
-
import { createSuccessResponse, createErrorResponse, getProvider, getWallet } from "./utils.js";
|
3
|
+
import { createSuccessResponse, createErrorResponse, getProvider, getWallet, setProvider } from "./utils.js";
|
4
4
|
import { fromPrivateKeyHandlerInput, createMnemonicPhraseHandlerInput } from "./wallet.types.js";
|
5
5
|
import { generateMnemonic, } from '@scure/bip39';
|
6
|
-
// Wallet Creation and Management
|
7
6
|
|
7
|
+
// Provider handlers
|
8
|
+
|
9
|
+
export const setProviderHandler = async (input: any): Promise<ToolResultSchema<any>> => {
|
10
|
+
try {
|
11
|
+
setProvider(input.providerURL);
|
12
|
+
return createSuccessResponse({}, `Provider set successfully:
|
13
|
+
Provider URL: ${input.providerURL}
|
14
|
+
`);
|
15
|
+
} catch (error) {
|
16
|
+
return createErrorResponse(`Failed to set provider: ${(error as Error).message}`);
|
17
|
+
}
|
18
|
+
};
|
19
|
+
|
20
|
+
|
21
|
+
// Wallet Creation and Management
|
8
22
|
export const createWalletHandler = async (input: any): Promise<ToolResultSchema<any>> => {
|
9
23
|
try {
|
10
24
|
const options: any = {};
|
@@ -50,7 +64,7 @@ export const fromPrivateKeyHandler = async (input: fromPrivateKeyHandlerInput):
|
|
50
64
|
return createErrorResponse("Private key is required");
|
51
65
|
}
|
52
66
|
|
53
|
-
const provider =
|
67
|
+
const provider = getProvider()
|
54
68
|
const wallet = new ethers.Wallet(input.privateKey, provider);
|
55
69
|
|
56
70
|
return createSuccessResponse({
|
@@ -98,7 +112,7 @@ export const fromMnemonicHandler = async (input: any): Promise<ToolResultSchema<
|
|
98
112
|
wordlist: (input.locale && ethers.wordlists[input.locale]) || ethers.wordlists.en
|
99
113
|
};
|
100
114
|
|
101
|
-
const provider =
|
115
|
+
const provider = getProvider();
|
102
116
|
const wallet = ethers.Wallet.fromMnemonic(input.mnemonic, options.path, options.wordlist);
|
103
117
|
|
104
118
|
if (provider) wallet.connect(provider);
|
@@ -129,7 +143,7 @@ export const fromEncryptedJsonHandler = async (input: any): Promise<ToolResultSc
|
|
129
143
|
}
|
130
144
|
|
131
145
|
const wallet = await ethers.Wallet.fromEncryptedJson(input.json, input.password);
|
132
|
-
const provider =
|
146
|
+
const provider = getProvider()
|
133
147
|
|
134
148
|
if (provider) {
|
135
149
|
wallet.connect(provider);
|
@@ -174,7 +188,9 @@ export const getAddressHandler = async (input: any): Promise<ToolResultSchema<an
|
|
174
188
|
|
175
189
|
return createSuccessResponse({
|
176
190
|
address: wallet.address
|
177
|
-
},
|
191
|
+
}, `Wallet address retrieved successfully:
|
192
|
+
Address: ${wallet.address}
|
193
|
+
`);
|
178
194
|
} catch (error) {
|
179
195
|
return createErrorResponse(`Failed to get wallet address: ${(error as Error).message}`);
|
180
196
|
}
|
@@ -186,7 +202,9 @@ export const getPublicKeyHandler = async (input: any): Promise<ToolResultSchema<
|
|
186
202
|
|
187
203
|
return createSuccessResponse({
|
188
204
|
publicKey: wallet.publicKey
|
189
|
-
},
|
205
|
+
}, `Wallet public key retrieved successfully:
|
206
|
+
Public Key: ${wallet.publicKey}
|
207
|
+
`);
|
190
208
|
} catch (error) {
|
191
209
|
return createErrorResponse(`Failed to get wallet public key: ${(error as Error).message}`);
|
192
210
|
}
|
@@ -198,7 +216,9 @@ export const getPrivateKeyHandler = async (input: any): Promise<ToolResultSchema
|
|
198
216
|
|
199
217
|
return createSuccessResponse({
|
200
218
|
privateKey: wallet.privateKey
|
201
|
-
},
|
219
|
+
}, `Wallet private key retrieved successfully:
|
220
|
+
Private Key: ${wallet.privateKey}
|
221
|
+
`);
|
202
222
|
} catch (error) {
|
203
223
|
return createErrorResponse(`Failed to get wallet private key: ${(error as Error).message}`);
|
204
224
|
}
|
@@ -207,11 +227,7 @@ export const getPrivateKeyHandler = async (input: any): Promise<ToolResultSchema
|
|
207
227
|
|
208
228
|
export const getBalanceHandler = async (input: any): Promise<ToolResultSchema<any>> => {
|
209
229
|
try {
|
210
|
-
|
211
|
-
return createErrorResponse("Provider URL is required to get balance");
|
212
|
-
}
|
213
|
-
|
214
|
-
const wallet = await getWallet(input.wallet, input.password, input.provider);
|
230
|
+
const wallet = await getWallet(input.wallet, input.password);
|
215
231
|
|
216
232
|
const balance = await wallet.getBalance(input.blockTag ?? "latest");
|
217
233
|
|
@@ -229,10 +245,10 @@ export const getBalanceHandler = async (input: any): Promise<ToolResultSchema<an
|
|
229
245
|
|
230
246
|
export const getChainIdHandler = async (input: any): Promise<ToolResultSchema<any>> => {
|
231
247
|
try {
|
232
|
-
const wallet = await getWallet(input.wallet, input.password
|
248
|
+
const wallet = await getWallet(input.wallet, input.password);
|
233
249
|
|
234
250
|
if (!wallet.provider) {
|
235
|
-
return createErrorResponse("Provider is required to get chain ID");
|
251
|
+
return createErrorResponse("Provider is required to get chain ID, please set the provider URL");
|
236
252
|
}
|
237
253
|
|
238
254
|
const chainId = await wallet.getChainId();
|
@@ -249,10 +265,10 @@ export const getChainIdHandler = async (input: any): Promise<ToolResultSchema<an
|
|
249
265
|
|
250
266
|
export const getGasPriceHandler = async (input: any): Promise<ToolResultSchema<any>> => {
|
251
267
|
try {
|
252
|
-
const wallet = await getWallet(input.wallet, input.password
|
268
|
+
const wallet = await getWallet(input.wallet, input.password);
|
253
269
|
|
254
270
|
if (!wallet.provider) {
|
255
|
-
return createErrorResponse("Provider is required to get gas price");
|
271
|
+
return createErrorResponse("Provider is required to get gas price, please set the provider URL");
|
256
272
|
}
|
257
273
|
|
258
274
|
const gasPrice = await wallet.getGasPrice();
|
@@ -271,10 +287,10 @@ export const getGasPriceHandler = async (input: any): Promise<ToolResultSchema<a
|
|
271
287
|
|
272
288
|
export const getTransactionCountHandler = async (input: any): Promise<ToolResultSchema<any>> => {
|
273
289
|
try {
|
274
|
-
const wallet = await getWallet(input.wallet, input.password
|
290
|
+
const wallet = await getWallet(input.wallet, input.password);
|
275
291
|
|
276
292
|
if (!wallet.provider) {
|
277
|
-
return createErrorResponse("Provider is required to get transaction count");
|
293
|
+
return createErrorResponse("Provider is required to get transaction count, please set the provider URL");
|
278
294
|
}
|
279
295
|
|
280
296
|
const transactionCount = await wallet.getTransactionCount(input.blockTag);
|
@@ -295,10 +311,10 @@ export const callHandler = async (input: any): Promise<ToolResultSchema<any>> =>
|
|
295
311
|
return createErrorResponse("Transaction is required");
|
296
312
|
}
|
297
313
|
|
298
|
-
const wallet = await getWallet(input.wallet, input.password
|
314
|
+
const wallet = await getWallet(input.wallet, input.password);
|
299
315
|
|
300
316
|
if (!wallet.provider) {
|
301
|
-
return createErrorResponse("Provider is required to call a contract");
|
317
|
+
return createErrorResponse("Provider is required to call a contract, please set the provider URL");
|
302
318
|
}
|
303
319
|
|
304
320
|
const result = await wallet.call(input.transaction, input.blockTag);
|
@@ -321,10 +337,9 @@ export const sendTransactionHandler = async (input: any): Promise<ToolResultSche
|
|
321
337
|
return createErrorResponse("Transaction is required");
|
322
338
|
}
|
323
339
|
|
324
|
-
const wallet = await getWallet(input.wallet, input.password
|
325
|
-
|
340
|
+
const wallet = await getWallet(input.wallet, input.password);
|
326
341
|
if (!wallet.provider) {
|
327
|
-
return createErrorResponse("Provider is required to send a transaction");
|
342
|
+
return createErrorResponse("Provider is required to send a transaction, please set the provider URL");
|
328
343
|
}
|
329
344
|
|
330
345
|
const tx = await wallet.sendTransaction(input.transaction);
|
@@ -358,7 +373,7 @@ export const signTransactionHandler = async (input: any): Promise<ToolResultSche
|
|
358
373
|
return createErrorResponse("Transaction is required");
|
359
374
|
}
|
360
375
|
|
361
|
-
const wallet = await getWallet(input.wallet, input.password
|
376
|
+
const wallet = await getWallet(input.wallet, input.password);
|
362
377
|
|
363
378
|
// For signing a transaction, we need to populate it first
|
364
379
|
const populatedTx = await wallet.populateTransaction(input.transaction);
|
@@ -380,10 +395,10 @@ export const populateTransactionHandler = async (input: any): Promise<ToolResult
|
|
380
395
|
return createErrorResponse("Transaction is required");
|
381
396
|
}
|
382
397
|
|
383
|
-
const wallet = await getWallet(input.wallet, input.password
|
398
|
+
const wallet = await getWallet(input.wallet, input.password);
|
384
399
|
|
385
400
|
if (!wallet.provider) {
|
386
|
-
return createErrorResponse("Provider is required to populate a transaction");
|
401
|
+
return createErrorResponse("Provider is required to populate a transaction, please set the provider URL");
|
387
402
|
}
|
388
403
|
|
389
404
|
const populatedTx = await wallet.populateTransaction(input.transaction);
|
@@ -530,15 +545,11 @@ export const verifyTypedDataHandler = async (input: any): Promise<ToolResultSche
|
|
530
545
|
|
531
546
|
export const getBlockHandler = async (input: any): Promise<ToolResultSchema<any>> => {
|
532
547
|
try {
|
533
|
-
if (!input.provider) {
|
534
|
-
return createErrorResponse("Provider is required");
|
535
|
-
}
|
536
|
-
|
537
548
|
if (!input.blockHashOrBlockTag) {
|
538
549
|
return createErrorResponse("Block hash or block tag is required");
|
539
550
|
}
|
540
551
|
|
541
|
-
const provider = getProvider(
|
552
|
+
const provider = getProvider();
|
542
553
|
// In ethers.js v5, getBlock can take includeTransactions as a second parameter
|
543
554
|
// but TypeScript definitions might not reflect this
|
544
555
|
const block = await (provider as any).getBlock(input.blockHashOrBlockTag, input.includeTransactions);
|
@@ -558,15 +569,11 @@ export const getBlockHandler = async (input: any): Promise<ToolResultSchema<any>
|
|
558
569
|
|
559
570
|
export const getTransactionHandler = async (input: any): Promise<ToolResultSchema<any>> => {
|
560
571
|
try {
|
561
|
-
if (!input.provider) {
|
562
|
-
return createErrorResponse("Provider is required");
|
563
|
-
}
|
564
|
-
|
565
572
|
if (!input.transactionHash) {
|
566
573
|
return createErrorResponse("Transaction hash is required");
|
567
574
|
}
|
568
575
|
|
569
|
-
const provider = getProvider(
|
576
|
+
const provider = getProvider();
|
570
577
|
const transaction = await provider.getTransaction(input.transactionHash);
|
571
578
|
|
572
579
|
return createSuccessResponse({
|
@@ -582,15 +589,11 @@ export const getTransactionHandler = async (input: any): Promise<ToolResultSchem
|
|
582
589
|
|
583
590
|
export const getTransactionReceiptHandler = async (input: any): Promise<ToolResultSchema<any>> => {
|
584
591
|
try {
|
585
|
-
if (!input.provider) {
|
586
|
-
return createErrorResponse("Provider is required");
|
587
|
-
}
|
588
|
-
|
589
592
|
if (!input.transactionHash) {
|
590
593
|
return createErrorResponse("Transaction hash is required");
|
591
594
|
}
|
592
595
|
|
593
|
-
const provider = getProvider(
|
596
|
+
const provider = getProvider();
|
594
597
|
const receipt = await provider.getTransactionReceipt(input.transactionHash);
|
595
598
|
|
596
599
|
return createSuccessResponse({
|
@@ -606,15 +609,11 @@ export const getTransactionReceiptHandler = async (input: any): Promise<ToolResu
|
|
606
609
|
|
607
610
|
export const getCodeHandler = async (input: any): Promise<ToolResultSchema<any>> => {
|
608
611
|
try {
|
609
|
-
if (!input.provider) {
|
610
|
-
return createErrorResponse("Provider is required");
|
611
|
-
}
|
612
|
-
|
613
612
|
if (!input.address) {
|
614
613
|
return createErrorResponse("Address is required");
|
615
614
|
}
|
616
615
|
|
617
|
-
const provider = getProvider(
|
616
|
+
const provider = getProvider();
|
618
617
|
const code = await provider.getCode(input.address, input.blockTag);
|
619
618
|
|
620
619
|
return createSuccessResponse({
|
@@ -630,10 +629,6 @@ export const getCodeHandler = async (input: any): Promise<ToolResultSchema<any>>
|
|
630
629
|
|
631
630
|
export const getStorageAtHandler = async (input: any): Promise<ToolResultSchema<any>> => {
|
632
631
|
try {
|
633
|
-
if (!input.provider) {
|
634
|
-
return createErrorResponse("Provider is required");
|
635
|
-
}
|
636
|
-
|
637
632
|
if (!input.address) {
|
638
633
|
return createErrorResponse("Address is required");
|
639
634
|
}
|
@@ -642,7 +637,7 @@ export const getStorageAtHandler = async (input: any): Promise<ToolResultSchema<
|
|
642
637
|
return createErrorResponse("Position is required");
|
643
638
|
}
|
644
639
|
|
645
|
-
const provider = getProvider(
|
640
|
+
const provider = getProvider();
|
646
641
|
const storage = await provider.getStorageAt(input.address, input.position, input.blockTag);
|
647
642
|
|
648
643
|
return createSuccessResponse({
|
@@ -659,15 +654,14 @@ export const getStorageAtHandler = async (input: any): Promise<ToolResultSchema<
|
|
659
654
|
|
660
655
|
export const estimateGasHandler = async (input: any): Promise<ToolResultSchema<any>> => {
|
661
656
|
try {
|
662
|
-
if (!input.provider) {
|
663
|
-
return createErrorResponse("Provider is required");
|
664
|
-
}
|
665
|
-
|
666
657
|
if (!input.transaction) {
|
667
658
|
return createErrorResponse("Transaction is required");
|
668
659
|
}
|
669
660
|
|
670
|
-
const provider = getProvider(
|
661
|
+
const provider = getProvider();
|
662
|
+
if (!provider) {
|
663
|
+
return createErrorResponse("Provider is required to estimate gas, please set the provider URL");
|
664
|
+
}
|
671
665
|
const gasEstimate = await provider.estimateGas(input.transaction);
|
672
666
|
|
673
667
|
return createSuccessResponse({
|
@@ -682,15 +676,14 @@ export const estimateGasHandler = async (input: any): Promise<ToolResultSchema<a
|
|
682
676
|
|
683
677
|
export const getLogsHandler = async (input: any): Promise<ToolResultSchema<any>> => {
|
684
678
|
try {
|
685
|
-
if (!input.provider) {
|
686
|
-
return createErrorResponse("Provider is required");
|
687
|
-
}
|
688
|
-
|
689
679
|
if (!input.filter) {
|
690
680
|
return createErrorResponse("Filter is required");
|
691
681
|
}
|
692
682
|
|
693
|
-
const provider = getProvider(
|
683
|
+
const provider = getProvider();
|
684
|
+
if (!provider) {
|
685
|
+
return createErrorResponse("Provider is required to get logs, please set the provider URL");
|
686
|
+
}
|
694
687
|
const logs = await provider.getLogs(input.filter);
|
695
688
|
|
696
689
|
return createSuccessResponse({
|
@@ -705,15 +698,14 @@ export const getLogsHandler = async (input: any): Promise<ToolResultSchema<any>>
|
|
705
698
|
|
706
699
|
export const getEnsResolverHandler = async (input: any): Promise<ToolResultSchema<any>> => {
|
707
700
|
try {
|
708
|
-
if (!input.provider) {
|
709
|
-
return createErrorResponse("Provider is required");
|
710
|
-
}
|
711
|
-
|
712
701
|
if (!input.name) {
|
713
702
|
return createErrorResponse("ENS name is required");
|
714
703
|
}
|
715
704
|
|
716
|
-
const provider = getProvider(
|
705
|
+
const provider = getProvider();
|
706
|
+
if (!provider) {
|
707
|
+
return createErrorResponse("Provider is required to get ENS resolver, please set the provider URL");
|
708
|
+
}
|
717
709
|
// In ethers.js v5, getResolver might not be directly on the provider type
|
718
710
|
// but it's available in the implementation
|
719
711
|
const resolver = await (provider as any).getResolver(input.name);
|
@@ -734,15 +726,14 @@ export const getEnsResolverHandler = async (input: any): Promise<ToolResultSchem
|
|
734
726
|
|
735
727
|
export const lookupAddressHandler = async (input: any): Promise<ToolResultSchema<any>> => {
|
736
728
|
try {
|
737
|
-
if (!input.provider) {
|
738
|
-
return createErrorResponse("Provider is required");
|
739
|
-
}
|
740
|
-
|
741
729
|
if (!input.address) {
|
742
730
|
return createErrorResponse("Address is required");
|
743
731
|
}
|
744
732
|
|
745
|
-
const provider = getProvider(
|
733
|
+
const provider = getProvider();
|
734
|
+
if (!provider) {
|
735
|
+
return createErrorResponse("Provider is required to lookup ENS name, please set the provider URL");
|
736
|
+
}
|
746
737
|
const name = await provider.lookupAddress(input.address);
|
747
738
|
|
748
739
|
return createSuccessResponse({
|
@@ -757,15 +748,14 @@ export const lookupAddressHandler = async (input: any): Promise<ToolResultSchema
|
|
757
748
|
|
758
749
|
export const resolveNameHandler = async (input: any): Promise<ToolResultSchema<any>> => {
|
759
750
|
try {
|
760
|
-
if (!input.provider) {
|
761
|
-
return createErrorResponse("Provider is required");
|
762
|
-
}
|
763
|
-
|
764
751
|
if (!input.name) {
|
765
752
|
return createErrorResponse("ENS name is required");
|
766
753
|
}
|
767
754
|
|
768
|
-
const provider = getProvider(
|
755
|
+
const provider = getProvider();
|
756
|
+
if (!provider) {
|
757
|
+
return createErrorResponse("Provider is required to resolve ENS name, please set the provider URL");
|
758
|
+
}
|
769
759
|
const address = await provider.resolveName(input.name);
|
770
760
|
|
771
761
|
return createSuccessResponse({
|
@@ -783,11 +773,10 @@ export const resolveNameHandler = async (input: any): Promise<ToolResultSchema<a
|
|
783
773
|
|
784
774
|
export const getNetworkHandler = async (input: any): Promise<ToolResultSchema<any>> => {
|
785
775
|
try {
|
786
|
-
|
787
|
-
|
776
|
+
const provider = getProvider();
|
777
|
+
if (!provider) {
|
778
|
+
return createErrorResponse("Provider is required to get network information, please set the provider URL");
|
788
779
|
}
|
789
|
-
|
790
|
-
const provider = getProvider(input.provider);
|
791
780
|
const network = await provider.getNetwork();
|
792
781
|
|
793
782
|
return createSuccessResponse({
|
@@ -808,11 +797,10 @@ export const getNetworkHandler = async (input: any): Promise<ToolResultSchema<an
|
|
808
797
|
|
809
798
|
export const getBlockNumberHandler = async (input: any): Promise<ToolResultSchema<any>> => {
|
810
799
|
try {
|
811
|
-
|
812
|
-
|
800
|
+
const provider = getProvider();
|
801
|
+
if (!provider) {
|
802
|
+
return createErrorResponse("Provider is required to get block number, please set the provider URL");
|
813
803
|
}
|
814
|
-
|
815
|
-
const provider = getProvider(input.provider);
|
816
804
|
const blockNumber = await provider.getBlockNumber();
|
817
805
|
|
818
806
|
return createSuccessResponse({
|
@@ -827,12 +815,10 @@ export const getBlockNumberHandler = async (input: any): Promise<ToolResultSchem
|
|
827
815
|
|
828
816
|
export const getFeeDataHandler = async (input: any): Promise<ToolResultSchema<any>> => {
|
829
817
|
try {
|
830
|
-
|
831
|
-
|
818
|
+
const provider = getProvider();
|
819
|
+
if (!provider) {
|
820
|
+
return createErrorResponse("Provider is required to get fee data, please set the provider URL");
|
832
821
|
}
|
833
|
-
|
834
|
-
const provider = getProvider(input.provider);
|
835
|
-
|
836
822
|
// getFeeData is available in ethers v5.5.0+
|
837
823
|
// @ts-ignore - getFeeData might not be in the type definitions depending on the version
|
838
824
|
const feeData = await provider.getFeeData();
|