web3-tools-mcp 1.3.1 → 1.3.2
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 +40 -3
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +3 -1
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/signatures.d.ts +18 -0
- package/dist/tools/signatures.d.ts.map +1 -1
- package/dist/tools/signatures.js +26 -1
- package/dist/tools/signatures.js.map +1 -1
- package/dist/tools/transactions.d.ts +111 -0
- package/dist/tools/transactions.d.ts.map +1 -0
- package/dist/tools/transactions.js +198 -0
- package/dist/tools/transactions.js.map +1 -0
- package/dist/wallet-server.d.ts +34 -0
- package/dist/wallet-server.d.ts.map +1 -0
- package/dist/wallet-server.js +195 -0
- package/dist/wallet-server.js.map +1 -0
- package/package.json +8 -1
- package/public/wallet-app.js +677 -0
- package/public/wallet.html +723 -0
- package/src/index.ts +8 -0
- package/src/tools/index.ts +3 -1
- package/src/tools/signatures.ts +34 -1
- package/src/tools/transactions.ts +246 -0
- package/src/wallet-server.ts +236 -0
package/README.md
CHANGED
|
@@ -5,11 +5,12 @@ A Model Context Protocol (MCP) server for blockchain interactions using [viem](h
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
7
|
- Multi-chain support (Ethereum, Arbitrum, Avalanche, Base, BNB Chain, Gnosis, Sonic, Optimism, Polygon, zkSync Era, Linea, Unichain)
|
|
8
|
-
-
|
|
8
|
+
- **🔐 Transaction Signing via Browser Wallet** (MetaMask, Rabby, Coinbase Wallet)
|
|
9
|
+
- Smart contract interactions (read & write functions, ABI retrieval, source code)
|
|
9
10
|
- Contract simulation & gas estimation (simulate transactions, estimate costs)
|
|
10
11
|
- Real-time gas price tracking (legacy & EIP-1559)
|
|
11
12
|
- ENS resolution (names ↔ addresses, text records, avatars)
|
|
12
|
-
- Token balances (native & ERC20, batch queries)
|
|
13
|
+
- Token balances & transfers (native & ERC20, batch queries)
|
|
13
14
|
- Event log queries with Hypersync acceleration
|
|
14
15
|
- Transaction tracing and analysis
|
|
15
16
|
- Storage slot reading with type decoding
|
|
@@ -80,6 +81,35 @@ npx web3-tools-mcp
|
|
|
80
81
|
| Unichain | 130 | ✅ |
|
|
81
82
|
| Localhost | 31337 | ❌ |
|
|
82
83
|
|
|
84
|
+
## 🔐 Browser Wallet Integration
|
|
85
|
+
|
|
86
|
+
The server includes a built-in wallet interface for secure transaction signing without exposing private keys.
|
|
87
|
+
|
|
88
|
+
### How It Works
|
|
89
|
+
|
|
90
|
+
1. When you use a transaction tool (e.g., `send_native_token`), the server automatically:
|
|
91
|
+
- Starts a local web server on `http://localhost:3456`
|
|
92
|
+
- Opens your browser to connect your wallet (MetaMask, Rabby, Coinbase Wallet, etc.)
|
|
93
|
+
2. You connect your wallet once in the browser
|
|
94
|
+
3. Transaction requests appear in the browser for approval
|
|
95
|
+
4. Sign or reject transactions directly in your wallet
|
|
96
|
+
|
|
97
|
+
### Supported Wallets
|
|
98
|
+
|
|
99
|
+
- MetaMask
|
|
100
|
+
- Rabby
|
|
101
|
+
- Coinbase Wallet
|
|
102
|
+
- Any browser wallet supporting EIP-1193
|
|
103
|
+
|
|
104
|
+
### Manual Access
|
|
105
|
+
|
|
106
|
+
Visit `http://localhost:3456` anytime to:
|
|
107
|
+
- Check wallet connection status
|
|
108
|
+
- See pending transactions
|
|
109
|
+
- View transaction history
|
|
110
|
+
|
|
111
|
+
**Note:** The wallet server runs automatically when the MCP server starts. No additional setup required!
|
|
112
|
+
|
|
83
113
|
## Available Tools
|
|
84
114
|
|
|
85
115
|
### Signatures
|
|
@@ -95,9 +125,16 @@ npx web3-tools-mcp
|
|
|
95
125
|
|
|
96
126
|
### Contract Interaction
|
|
97
127
|
- `call_contract_function` - Call view/pure functions (supports batch)
|
|
128
|
+
- `call_contract_write` - Execute state-changing contract functions via browser wallet
|
|
129
|
+
- `simulate_contract` - Simulate contract calls without broadcasting (includes gas estimate)
|
|
130
|
+
|
|
131
|
+
### Transactions (Browser Wallet Required)
|
|
132
|
+
- `send_native_token` - Send ETH/native tokens to an address
|
|
133
|
+
- `send_erc20_token` - Send ERC20 tokens to an address
|
|
134
|
+
- `sign_message` - Sign messages with your wallet
|
|
135
|
+
- `wallet_status` - Check wallet connection status
|
|
98
136
|
|
|
99
137
|
### Gas & Simulation
|
|
100
|
-
- `simulate_contract` - Simulate contract calls without broadcasting (includes gas estimate)
|
|
101
138
|
- `estimate_gas` - Estimate gas cost for any transaction
|
|
102
139
|
- `get_gas_price` - Get current gas prices (legacy & EIP-1559)
|
|
103
140
|
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
|
|
|
5
5
|
import { initializeClientManager } from "./client.js";
|
|
6
6
|
import { registerAllTools } from "./tools/index.js";
|
|
7
7
|
import { parseCommandLineArgs } from "./utils.js";
|
|
8
|
+
import { startWalletServer } from "./wallet-server.js";
|
|
8
9
|
// Parse configuration
|
|
9
10
|
const config = parseCommandLineArgs();
|
|
10
11
|
// Show help if requested
|
|
@@ -75,11 +76,17 @@ const server = new McpServer({
|
|
|
75
76
|
});
|
|
76
77
|
// Register all tools
|
|
77
78
|
registerAllTools(server);
|
|
79
|
+
// Start wallet server in background
|
|
80
|
+
startWalletServer().catch((error) => {
|
|
81
|
+
console.error("[MCP] Wallet server failed to start:", error.message);
|
|
82
|
+
console.error("[MCP] Transaction signing features will not be available");
|
|
83
|
+
});
|
|
78
84
|
// Start server
|
|
79
85
|
async function main() {
|
|
80
86
|
const transport = new StdioServerTransport();
|
|
81
87
|
await server.connect(transport);
|
|
82
88
|
console.error("Web3 Tools MCP Server running on stdio");
|
|
89
|
+
console.error("Wallet interface available at http://localhost:3456");
|
|
83
90
|
}
|
|
84
91
|
main().catch((error) => {
|
|
85
92
|
console.error("Fatal error:", error);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,WAAW,MAAM,iBAAiB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,WAAW,MAAM,iBAAiB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD,sBAAsB;AACtB,MAAM,MAAM,GAAG,oBAAoB,EAAE,CAAC;AAEtC,yBAAyB;AACzB,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;IACpB,OAAO,CAAC,GAAG,CAAC;yBACW,WAAW,CAAC,OAAO;EAC1C,WAAW,CAAC,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAmCb,WAAW,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;YAClE,WAAW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CAAC,wCAAwC,CAAC,CAAC;IACxD,OAAO,CAAC,KAAK,CAAC,qDAAqD,CAAC,CAAC;AACvE,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AA0BnE,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,QAcjD"}
|
package/dist/tools/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import ensTools from './ens.js';
|
|
|
6
6
|
import gasTools from './gas.js';
|
|
7
7
|
import logTools from './logs.js';
|
|
8
8
|
import signatureTools from './signatures.js';
|
|
9
|
+
import transactionTools from './transactions.js';
|
|
9
10
|
const allToolDefinitions = {
|
|
10
11
|
...signatureTools,
|
|
11
12
|
...contractTools,
|
|
@@ -14,7 +15,8 @@ const allToolDefinitions = {
|
|
|
14
15
|
...logTools,
|
|
15
16
|
...advancedTools,
|
|
16
17
|
...ensTools,
|
|
17
|
-
...gasTools
|
|
18
|
+
...gasTools,
|
|
19
|
+
...transactionTools
|
|
18
20
|
};
|
|
19
21
|
// Register all tools with the MCP server
|
|
20
22
|
export function registerAllTools(server) {
|
package/dist/tools/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAGA,OAAO,aA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,KAAK;SAC/B,EACD,KAAK,EAAE,IAAS,EAAE,MAA8D,EAAE,EAAE;YAClF,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QACjC,CAAC,CACF,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -78,6 +78,24 @@ declare const _default: {
|
|
|
78
78
|
}[];
|
|
79
79
|
}) => Promise<import("../types.js").ToolResult>;
|
|
80
80
|
};
|
|
81
|
+
encode_function_data: {
|
|
82
|
+
title: string;
|
|
83
|
+
description: string;
|
|
84
|
+
schema: z.ZodObject<{
|
|
85
|
+
functionAbi: z.ZodString;
|
|
86
|
+
args: z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]>, "many">;
|
|
87
|
+
}, "strip", z.ZodTypeAny, {
|
|
88
|
+
args: (string | number | boolean)[];
|
|
89
|
+
functionAbi: string;
|
|
90
|
+
}, {
|
|
91
|
+
args: (string | number | boolean)[];
|
|
92
|
+
functionAbi: string;
|
|
93
|
+
}>;
|
|
94
|
+
handler: (args: {
|
|
95
|
+
args: (string | number | boolean)[];
|
|
96
|
+
functionAbi: string;
|
|
97
|
+
}) => Promise<import("../types.js").ToolResult>;
|
|
98
|
+
};
|
|
81
99
|
};
|
|
82
100
|
export default _default;
|
|
83
101
|
//# sourceMappingURL=signatures.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signatures.d.ts","sourceRoot":"","sources":["../../src/tools/signatures.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"signatures.d.ts","sourceRoot":"","sources":["../../src/tools/signatures.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBvB,wBA+HC"}
|
package/dist/tools/signatures.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { keccak256, parseAbiItem, toBytes, toEventSignature, toFunctionSignature } from 'viem';
|
|
1
|
+
import { keccak256, parseAbiItem, toBytes, toEventSignature, toFunctionSignature, encodeFunctionData } from 'viem';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { createTool, formatResponse } from '../utils.js';
|
|
4
4
|
const FunctionAbiSchema = z.object({
|
|
@@ -88,6 +88,31 @@ export default {
|
|
|
88
88
|
catch (error) {
|
|
89
89
|
throw new Error(`Failed to parse error ABI: ${error}`);
|
|
90
90
|
}
|
|
91
|
+
}),
|
|
92
|
+
encode_function_data: createTool('Encode Function Call Data', 'Encode a function call with parameters into transaction data. Use this before calling call_contract_write.', z.object({
|
|
93
|
+
functionAbi: z.string().describe('Function ABI definition (e.g., "function transfer(address to, uint256 amount)")'),
|
|
94
|
+
args: z.array(z.union([z.string(), z.number(), z.boolean()])).describe('Function arguments in order matching the ABI signature. Automatically type-converted.')
|
|
95
|
+
}), async (args) => {
|
|
96
|
+
try {
|
|
97
|
+
const abiItem = parseAbiItem(args.functionAbi);
|
|
98
|
+
// Encode the function data
|
|
99
|
+
const data = encodeFunctionData({
|
|
100
|
+
abi: [abiItem],
|
|
101
|
+
functionName: abiItem.name,
|
|
102
|
+
args: args.args
|
|
103
|
+
});
|
|
104
|
+
return formatResponse({
|
|
105
|
+
data,
|
|
106
|
+
functionName: abiItem.name,
|
|
107
|
+
functionSignature: toFunctionSignature(abiItem),
|
|
108
|
+
selector: data.slice(0, 10),
|
|
109
|
+
encodedArgs: data.slice(10),
|
|
110
|
+
message: 'Function data encoded successfully. Use this data with call_contract_write tool.'
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
throw new Error(`Failed to encode function data: ${error}`);
|
|
115
|
+
}
|
|
91
116
|
})
|
|
92
117
|
};
|
|
93
118
|
//# sourceMappingURL=signatures.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signatures.js","sourceRoot":"","sources":["../../src/tools/signatures.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,SAAS,EACT,YAAY,EACZ,OAAO,EACP,gBAAgB,EAChB,mBAAmB,
|
|
1
|
+
{"version":3,"file":"signatures.js","sourceRoot":"","sources":["../../src/tools/signatures.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,SAAS,EACT,YAAY,EACZ,OAAO,EACP,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,MAAM,CAAA;AACb,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAExD,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,iFAAiF,CAAC;CACpH,CAAC,CAAA;AAEF,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9B,QAAQ,EAAE,CAAC;SACR,MAAM,EAAE;SACR,QAAQ,CAAC,wGAAwG,CAAC;CACtH,CAAC,CAAA;AAEF,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9B,QAAQ,EAAE,CAAC;SACR,MAAM,EAAE;SACR,QAAQ,CAAC,+FAA+F,CAAC;CAC7G,CAAC,CAAA;AAEF,eAAe;IACb,sBAAsB,EAAE,UAAU,CAChC,+BAA+B,EAC/B,0GAA0G,EAC1G,CAAC,CAAC,MAAM,CAAC;QACP,KAAK,EAAE,CAAC;aACL,KAAK,CAAC,iBAAiB,CAAC;aACxB,QAAQ,CAAC,6EAA6E,CAAC;KAC3F,CAAC,EACF,KAAK,EAAE,IAAI,EAAE,EAAE;QACb,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;gBACtC,MA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AC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;gBAC3B,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC3B,OAAO,EAAE,kFAAkF;aAC5F,CAAC,CAAA;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,mCAAmC,KAAK,EAAE,CAAC,CAAA;QAC7D,CAAC;IACH,CAAC,CACF;CACF,CAAA"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
declare const _default: {
|
|
3
|
+
send_native_token: {
|
|
4
|
+
title: string;
|
|
5
|
+
description: string;
|
|
6
|
+
schema: z.ZodObject<{
|
|
7
|
+
chain: z.ZodEnum<["mainnet", "arbitrum", "avalanche", "base", "bnb", "gnosis", "sonic", "optimism", "polygon", "zksync", "linea", "unichain", "localhost"]>;
|
|
8
|
+
to: z.ZodString;
|
|
9
|
+
amount: z.ZodString;
|
|
10
|
+
data: z.ZodOptional<z.ZodString>;
|
|
11
|
+
}, "strip", z.ZodTypeAny, {
|
|
12
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
13
|
+
to: string;
|
|
14
|
+
amount: string;
|
|
15
|
+
data?: string | undefined;
|
|
16
|
+
}, {
|
|
17
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
18
|
+
to: string;
|
|
19
|
+
amount: string;
|
|
20
|
+
data?: string | undefined;
|
|
21
|
+
}>;
|
|
22
|
+
handler: (args: {
|
|
23
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
24
|
+
to: string;
|
|
25
|
+
amount: string;
|
|
26
|
+
data?: string | undefined;
|
|
27
|
+
}) => Promise<import("../types.js").ToolResult>;
|
|
28
|
+
};
|
|
29
|
+
send_erc20_token: {
|
|
30
|
+
title: string;
|
|
31
|
+
description: string;
|
|
32
|
+
schema: z.ZodObject<{
|
|
33
|
+
chain: z.ZodEnum<["mainnet", "arbitrum", "avalanche", "base", "bnb", "gnosis", "sonic", "optimism", "polygon", "zksync", "linea", "unichain", "localhost"]>;
|
|
34
|
+
tokenAddress: z.ZodString;
|
|
35
|
+
to: z.ZodString;
|
|
36
|
+
amount: z.ZodString;
|
|
37
|
+
decimals: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
38
|
+
}, "strip", z.ZodTypeAny, {
|
|
39
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
40
|
+
to: string;
|
|
41
|
+
tokenAddress: string;
|
|
42
|
+
decimals: number;
|
|
43
|
+
amount: string;
|
|
44
|
+
}, {
|
|
45
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
46
|
+
to: string;
|
|
47
|
+
tokenAddress: string;
|
|
48
|
+
amount: string;
|
|
49
|
+
decimals?: number | undefined;
|
|
50
|
+
}>;
|
|
51
|
+
handler: (args: {
|
|
52
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
53
|
+
to: string;
|
|
54
|
+
tokenAddress: string;
|
|
55
|
+
decimals: number;
|
|
56
|
+
amount: string;
|
|
57
|
+
}) => Promise<import("../types.js").ToolResult>;
|
|
58
|
+
};
|
|
59
|
+
call_contract_write: {
|
|
60
|
+
title: string;
|
|
61
|
+
description: string;
|
|
62
|
+
schema: z.ZodObject<{
|
|
63
|
+
chain: z.ZodEnum<["mainnet", "arbitrum", "avalanche", "base", "bnb", "gnosis", "sonic", "optimism", "polygon", "zksync", "linea", "unichain", "localhost"]>;
|
|
64
|
+
contractAddress: z.ZodString;
|
|
65
|
+
functionAbi: z.ZodString;
|
|
66
|
+
args: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]>, "many">>;
|
|
67
|
+
value: z.ZodOptional<z.ZodString>;
|
|
68
|
+
}, "strip", z.ZodTypeAny, {
|
|
69
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
70
|
+
contractAddress: string;
|
|
71
|
+
functionAbi: string;
|
|
72
|
+
value?: string | undefined;
|
|
73
|
+
args?: (string | number | boolean)[] | undefined;
|
|
74
|
+
}, {
|
|
75
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
76
|
+
contractAddress: string;
|
|
77
|
+
functionAbi: string;
|
|
78
|
+
value?: string | undefined;
|
|
79
|
+
args?: (string | number | boolean)[] | undefined;
|
|
80
|
+
}>;
|
|
81
|
+
handler: (args: {
|
|
82
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
83
|
+
contractAddress: string;
|
|
84
|
+
functionAbi: string;
|
|
85
|
+
value?: string | undefined;
|
|
86
|
+
args?: (string | number | boolean)[] | undefined;
|
|
87
|
+
}) => Promise<import("../types.js").ToolResult>;
|
|
88
|
+
};
|
|
89
|
+
sign_message: {
|
|
90
|
+
title: string;
|
|
91
|
+
description: string;
|
|
92
|
+
schema: z.ZodObject<{
|
|
93
|
+
message: z.ZodString;
|
|
94
|
+
}, "strip", z.ZodTypeAny, {
|
|
95
|
+
message: string;
|
|
96
|
+
}, {
|
|
97
|
+
message: string;
|
|
98
|
+
}>;
|
|
99
|
+
handler: (args: {
|
|
100
|
+
message: string;
|
|
101
|
+
}) => Promise<import("../types.js").ToolResult>;
|
|
102
|
+
};
|
|
103
|
+
wallet_status: {
|
|
104
|
+
title: string;
|
|
105
|
+
description: string;
|
|
106
|
+
schema: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
|
|
107
|
+
handler: (args: {}) => Promise<import("../types.js").ToolResult>;
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
export default _default;
|
|
111
|
+
//# sourceMappingURL=transactions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transactions.d.ts","sourceRoot":"","sources":["../../src/tools/transactions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWvB,wBAyOC"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { getWalletServer } from '../wallet-server.js';
|
|
3
|
+
import { SUPPORTED_CHAINS } from '../client.js';
|
|
4
|
+
import { parseUnits, encodeFunctionData, parseAbiItem } from 'viem';
|
|
5
|
+
import { randomBytes } from 'crypto';
|
|
6
|
+
import { createTool, formatResponse } from '../utils.js';
|
|
7
|
+
function generateRequestId() {
|
|
8
|
+
return randomBytes(16).toString('hex');
|
|
9
|
+
}
|
|
10
|
+
export default {
|
|
11
|
+
send_native_token: createTool('Send Native Token', 'Send native tokens (ETH, MATIC, BNB, etc.) to an address. Opens browser wallet for approval.', z.object({
|
|
12
|
+
chain: z.enum(SUPPORTED_CHAINS).describe('Blockchain network'),
|
|
13
|
+
to: z.string().describe('Recipient address'),
|
|
14
|
+
amount: z.string().describe('Amount in native token (e.g., "0.1" for 0.1 ETH)'),
|
|
15
|
+
data: z.string().optional().describe('Optional hex-encoded data to include with transaction')
|
|
16
|
+
}), async (args) => {
|
|
17
|
+
const walletServer = getWalletServer();
|
|
18
|
+
try {
|
|
19
|
+
// Parse amount to wei
|
|
20
|
+
const value = '0x' + parseUnits(args.amount, 18).toString(16);
|
|
21
|
+
const txRequest = {
|
|
22
|
+
id: generateRequestId(),
|
|
23
|
+
type: 'send_transaction',
|
|
24
|
+
chain: args.chain,
|
|
25
|
+
data: {
|
|
26
|
+
to: args.to,
|
|
27
|
+
value,
|
|
28
|
+
...(args.data && { data: args.data })
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
console.error(`[Transaction] Sending ${args.amount} native token to ${args.to} on ${args.chain}`);
|
|
32
|
+
const txHash = await walletServer.sendTransaction(txRequest);
|
|
33
|
+
return formatResponse({
|
|
34
|
+
success: true,
|
|
35
|
+
chain: args.chain,
|
|
36
|
+
transactionHash: txHash,
|
|
37
|
+
to: args.to,
|
|
38
|
+
amount: args.amount,
|
|
39
|
+
message: `Successfully sent ${args.amount} native token`,
|
|
40
|
+
explorerUrl: `https://etherscan.io/tx/${txHash}`
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
45
|
+
return formatResponse({
|
|
46
|
+
success: false,
|
|
47
|
+
error: errorMessage,
|
|
48
|
+
message: 'Transaction failed or was rejected'
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}),
|
|
52
|
+
send_erc20_token: createTool('Send ERC20 Token', 'Send ERC20 tokens to an address. Opens browser wallet for approval.', z.object({
|
|
53
|
+
chain: z.enum(SUPPORTED_CHAINS).describe('Blockchain network'),
|
|
54
|
+
tokenAddress: z.string().describe('ERC20 token contract address'),
|
|
55
|
+
to: z.string().describe('Recipient address'),
|
|
56
|
+
amount: z.string().describe('Amount in token units (e.g., "100" for 100 USDC)'),
|
|
57
|
+
decimals: z.number().optional().default(18).describe('Token decimals (default: 18)')
|
|
58
|
+
}), async (args) => {
|
|
59
|
+
const walletServer = getWalletServer();
|
|
60
|
+
try {
|
|
61
|
+
const decimals = args.decimals || 18;
|
|
62
|
+
const amountWei = parseUnits(args.amount, decimals);
|
|
63
|
+
// ERC20 transfer(address to, uint256 amount)
|
|
64
|
+
const data = `0xa9059cbb${args.to.slice(2).padStart(64, '0')}${amountWei.toString(16).padStart(64, '0')}`;
|
|
65
|
+
const txRequest = {
|
|
66
|
+
id: generateRequestId(),
|
|
67
|
+
type: 'send_transaction',
|
|
68
|
+
chain: args.chain,
|
|
69
|
+
data: {
|
|
70
|
+
to: args.tokenAddress,
|
|
71
|
+
data,
|
|
72
|
+
value: '0x0'
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
console.error(`[Transaction] Sending ${args.amount} tokens to ${args.to} on ${args.chain}`);
|
|
76
|
+
const txHash = await walletServer.sendTransaction(txRequest);
|
|
77
|
+
return formatResponse({
|
|
78
|
+
success: true,
|
|
79
|
+
chain: args.chain,
|
|
80
|
+
transactionHash: txHash,
|
|
81
|
+
tokenAddress: args.tokenAddress,
|
|
82
|
+
to: args.to,
|
|
83
|
+
amount: args.amount,
|
|
84
|
+
message: `Successfully sent ${args.amount} tokens`,
|
|
85
|
+
explorerUrl: `https://etherscan.io/tx/${txHash}`
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
90
|
+
return formatResponse({
|
|
91
|
+
success: false,
|
|
92
|
+
error: errorMessage,
|
|
93
|
+
message: 'Token transfer failed or was rejected'
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}),
|
|
97
|
+
call_contract_write: createTool('Call Contract (Write)', 'Call a state-changing contract function (write operation). Opens browser wallet for approval.', z.object({
|
|
98
|
+
chain: z.enum(SUPPORTED_CHAINS).describe('Blockchain network'),
|
|
99
|
+
contractAddress: z.string().describe('Contract address'),
|
|
100
|
+
functionAbi: z.string().describe('Function ABI definition (e.g., "function transfer(address to, uint256 amount)")'),
|
|
101
|
+
args: z.array(z.union([z.string(), z.number(), z.boolean()])).optional().describe('Function arguments in order matching the ABI signature'),
|
|
102
|
+
value: z.string().optional().describe('Optional ETH value to send with transaction (in ETH units, e.g., "0.1")')
|
|
103
|
+
}), async (args) => {
|
|
104
|
+
const walletServer = getWalletServer();
|
|
105
|
+
try {
|
|
106
|
+
// Parse the function ABI and encode the call data
|
|
107
|
+
console.error(`[Transaction] Parsing ABI: ${args.functionAbi}`);
|
|
108
|
+
console.error(`[Transaction] Args: ${JSON.stringify(args.args)}`);
|
|
109
|
+
const abiItem = parseAbiItem(args.functionAbi);
|
|
110
|
+
console.error(`[Transaction] Parsed function: ${abiItem.name}`);
|
|
111
|
+
const data = encodeFunctionData({
|
|
112
|
+
abi: [abiItem],
|
|
113
|
+
functionName: abiItem.name,
|
|
114
|
+
args: (args.args || [])
|
|
115
|
+
});
|
|
116
|
+
console.error(`[Transaction] Encoded data: ${data}`);
|
|
117
|
+
const valueHex = args.value ? '0x' + parseUnits(args.value, 18).toString(16) : '0x0';
|
|
118
|
+
const txRequest = {
|
|
119
|
+
id: generateRequestId(),
|
|
120
|
+
type: 'send_transaction',
|
|
121
|
+
chain: args.chain,
|
|
122
|
+
data: {
|
|
123
|
+
to: args.contractAddress,
|
|
124
|
+
data,
|
|
125
|
+
value: valueHex
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
console.error(`[Transaction] Calling ${abiItem.name}() on ${args.contractAddress} (${args.chain})`);
|
|
129
|
+
const txHash = await walletServer.sendTransaction(txRequest);
|
|
130
|
+
return formatResponse({
|
|
131
|
+
success: true,
|
|
132
|
+
chain: args.chain,
|
|
133
|
+
transactionHash: txHash,
|
|
134
|
+
contractAddress: args.contractAddress,
|
|
135
|
+
functionName: abiItem.name,
|
|
136
|
+
message: `Contract call to ${abiItem.name}() successful`,
|
|
137
|
+
explorerUrl: `https://etherscan.io/tx/${txHash}`
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
console.error(`[Transaction] Error:`, error);
|
|
142
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
143
|
+
return formatResponse({
|
|
144
|
+
success: false,
|
|
145
|
+
error: errorMessage,
|
|
146
|
+
message: 'Contract call failed or was rejected'
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}),
|
|
150
|
+
sign_message: createTool('Sign Message', 'Sign a message with the connected wallet. Opens browser wallet for approval.', z.object({
|
|
151
|
+
message: z.string().describe('Message to sign')
|
|
152
|
+
}), async (args) => {
|
|
153
|
+
const walletServer = getWalletServer();
|
|
154
|
+
try {
|
|
155
|
+
const request = {
|
|
156
|
+
id: generateRequestId(),
|
|
157
|
+
type: 'sign_message',
|
|
158
|
+
chain: 'any',
|
|
159
|
+
data: {
|
|
160
|
+
message: args.message
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
console.error(`[Transaction] Signing message`);
|
|
164
|
+
const signature = await walletServer.sendTransaction(request);
|
|
165
|
+
return formatResponse({
|
|
166
|
+
success: true,
|
|
167
|
+
message: args.message,
|
|
168
|
+
signature,
|
|
169
|
+
signatureType: 'personal_sign'
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
174
|
+
return formatResponse({
|
|
175
|
+
success: false,
|
|
176
|
+
error: errorMessage,
|
|
177
|
+
message: 'Message signing failed or was rejected'
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}),
|
|
181
|
+
wallet_status: createTool('Wallet Status', 'Check if a wallet is connected to the browser interface', z.object({}), async () => {
|
|
182
|
+
const walletServer = getWalletServer();
|
|
183
|
+
const isConnected = walletServer.isConnected();
|
|
184
|
+
const port = walletServer.getPort();
|
|
185
|
+
// Auto-open browser if no wallet connected
|
|
186
|
+
if (!isConnected) {
|
|
187
|
+
walletServer.openBrowser();
|
|
188
|
+
}
|
|
189
|
+
return formatResponse({
|
|
190
|
+
connected: isConnected,
|
|
191
|
+
walletUrl: `http://localhost:${port}`,
|
|
192
|
+
message: isConnected
|
|
193
|
+
? 'Wallet is connected and ready to sign transactions'
|
|
194
|
+
: `No wallet connected. Opening browser to connect... Visit http://localhost:${port} if it didn't open automatically.`
|
|
195
|
+
});
|
|
196
|
+
})
|
|
197
|
+
};
|
|
198
|
+
//# sourceMappingURL=transactions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transactions.js","sourceRoot":"","sources":["../../src/tools/transactions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,YAAY,EAAoB,MAAM,MAAM,CAAA;AACrF,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AACpC,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAExD,SAAS,iBAAiB;IACxB,OAAO,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;AACxC,CAAC;AAED,eAAe;IACb,iBAAiB,EAAE,UAAU,CAC3B,mBAAmB,EACnB,8FAA8F,EAC9F,CAAC,CAAC,MAAM,CAAC;QACP,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,QAAQ,CAAC,oBAAoB,CAAC;QAC9D,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,mBAAmB,CAAC;QAC5C,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,kDAAkD,CAAC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AAG,YAAY,CAAC,WAAW,EAAE,CAAA;QAC9C,MAAM,IAAI,GAAG,YAAY,CAAC,OAAO,EAAE,CAAA;QAEnC,2CAA2C;QAC3C,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,YAAY,CAAC,WAAW,EAAE,CAAA;QAC5B,CAAC;QAED,OAAO,cAAc,CAAC;YACpB,SAAS,EAAE,WAAW;YACtB,SAAS,EAAE,oBAAoB,IAAI,EAAE;YACrC,OAAO,EAAE,WAAW;gBAClB,CAAC,CAAC,oDAAoD;gBACtD,CAAC,CAAC,6EAA6E,IAAI,mCAAmC;SACzH,CAAC,CAAA;IACJ,CAAC,CACF;CACF,CAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export interface TransactionRequest {
|
|
2
|
+
id: string;
|
|
3
|
+
type: 'send_transaction' | 'sign_message' | 'sign_typed_data';
|
|
4
|
+
chain: string;
|
|
5
|
+
data: unknown;
|
|
6
|
+
}
|
|
7
|
+
export interface TransactionResponse {
|
|
8
|
+
id: string;
|
|
9
|
+
success: boolean;
|
|
10
|
+
result?: unknown;
|
|
11
|
+
error?: string;
|
|
12
|
+
}
|
|
13
|
+
declare class WalletServer {
|
|
14
|
+
private app;
|
|
15
|
+
private httpServer;
|
|
16
|
+
private wss;
|
|
17
|
+
private clients;
|
|
18
|
+
private pendingRequests;
|
|
19
|
+
private port;
|
|
20
|
+
private isStarted;
|
|
21
|
+
constructor(port?: number);
|
|
22
|
+
private setupExpress;
|
|
23
|
+
private setupWebSocket;
|
|
24
|
+
start(): Promise<void>;
|
|
25
|
+
stop(): Promise<void>;
|
|
26
|
+
openBrowser(): void;
|
|
27
|
+
sendTransaction(request: TransactionRequest): Promise<unknown>;
|
|
28
|
+
isConnected(): boolean;
|
|
29
|
+
getPort(): number;
|
|
30
|
+
}
|
|
31
|
+
export declare function getWalletServer(): WalletServer;
|
|
32
|
+
export declare function startWalletServer(): Promise<WalletServer>;
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=wallet-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet-server.d.ts","sourceRoot":"","sources":["../src/wallet-server.ts"],"names":[],"mappings":"AAWA,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,kBAAkB,GAAG,cAAc,GAAG,iBAAiB,CAAA;IAC7D,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,OAAO,CAAA;CACd;AAED,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAA;IACV,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,cAAM,YAAY;IAChB,OAAO,CAAC,GAAG,CAAqB;IAChC,OAAO,CAAC,UAAU,CAAiC;IACnD,OAAO,CAAC,GAAG,CAAiB;IAC5B,OAAO,CAAC,OAAO,CAA4B;IAC3C,OAAO,CAAC,eAAe,CAGT;IACd,OAAO,CAAC,IAAI,CAAQ;IACpB,OAAO,CAAC,SAAS,CAAQ;gBAEb,IAAI,SAAO;IAUvB,OAAO,CAAC,YAAY;IAkBpB,OAAO,CAAC,cAAc;IAqChB,KAAK;IAsBL,IAAI;IAaV,WAAW;IAuBL,eAAe,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,OAAO,CAAC;IAoDpE,WAAW,IAAI,OAAO;IAItB,OAAO,IAAI,MAAM;CAGlB;AAKD,wBAAgB,eAAe,IAAI,YAAY,CAK9C;AAED,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,YAAY,CAAC,CAI/D"}
|