wallet_sign_transaction
Sign Ethereum and EVM-compatible blockchain transactions securely without broadcasting. Provide wallet details and transaction data to generate a signed transaction for offline use or later submission.
Instructions
Sign a transaction without sending it
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| transaction | Yes | The transaction to sign | |
| wallet | No | The wallet (private key, mnemonic, or JSON). If not provided, uses PRIVATE_KEY environment variable if set. |
Implementation Reference
- src/handlers/wallet.ts:345-364 (handler)The main handler function that populates the transaction if needed and signs it using the Ethers.js Wallet instance.export const signTransactionHandler = async (input: any): Promise<ToolResultSchema> => { try { if (!input.transaction) { return createErrorResponse("Transaction is required"); } const wallet = await getWallet(input.wallet, input.password); // For signing a transaction, we need to populate it first const populatedTx = await wallet.populateTransaction(input.transaction); const signedTx = await wallet.signTransaction(populatedTx); return createSuccessResponse( `Transaction signed successfully Signed transaction: ${signedTx} `); } catch (error) { return createErrorResponse(`Failed to sign transaction: ${(error as Error).message}`); } };
- src/tools.ts:277-304 (schema)Defines the tool name, description, and input schema for 'wallet_sign_transaction' in the tools array.{ name: "wallet_sign_transaction", description: "Sign a transaction without sending it", inputSchema: { type: "object", properties: { wallet: { type: "string", description: "The wallet (private key, mnemonic, or JSON). If not provided, uses PRIVATE_KEY environment variable if set." }, transaction: { type: "object", description: "The transaction to sign", properties: { to: { type: "string" }, from: { type: "string" }, data: { type: "string" }, value: { type: "string" }, gasLimit: { type: "string" }, gasPrice: { type: "string" }, nonce: { type: "number" }, type: { type: "number" }, maxFeePerGas: { type: "string" }, maxPriorityFeePerGas: { type: "string" } }, required: ["to"] } }, required: ["transaction"] } },
- src/tools.ts:579-581 (registration)Registers the signTransactionHandler function to the 'wallet_sign_transaction' tool name in the handlers dictionary."wallet_send_transaction": sendTransactionHandler, "wallet_sign_transaction": signTransactionHandler, "wallet_populate_transaction": populateTransactionHandler,
- src/tools.ts:16-37 (registration)Imports the signTransactionHandler from the handlers module.signTransactionHandler, populateTransactionHandler, signMessageHandler, signTypedDataHandler, verifyMessageHandler, verifyTypedDataHandler, getBlockHandler, getTransactionHandler, getTransactionReceiptHandler, getCodeHandler, getStorageAtHandler, estimateGasHandler, getLogsHandler, getEnsResolverHandler, lookupAddressHandler, resolveNameHandler, getNetworkHandler, getBlockNumberHandler, getFeeDataHandler, createMnemonicPhraseHandler, setProviderHandler } from "./handlers/wallet.js";