Skip to main content
Glama

prepareTransaction

Prepare ETH transfer transactions for signing by specifying sender, recipient, amount, and gas parameters. Generates transaction data ready for blockchain submission.

Instructions

Prepare a basic ETH transfer transaction for signing. Returns transaction data that can be signed and broadcast.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
toAddressYesThe Ethereum address to send ETH to
valueYesThe amount to send in ETH (e.g., '1.0', '0.5')
fromAddressYesThe Ethereum address sending the ETH
providerNoOptional. Either a network name or custom RPC URL. Use getAllNetworks to see available networks and their details, or getNetwork to get info about a specific network. You can use any network name returned by these tools as a provider value.
chainIdNoOptional. The chain ID to use.
gasLimitNoOptional. The gas limit for the transaction
gasPriceNoOptional. The gas price (in gwei) for legacy transactions
maxFeePerGasNoOptional. The maximum fee per gas (in gwei) for EIP-1559 transactions
maxPriorityFeePerGasNoOptional. The maximum priority fee per gas (in gwei) for EIP-1559 transactions

Implementation Reference

  • Registration of the MCP tool 'prepareTransaction' using server.tool(). This includes the tool name, description, input schema, and the handler function that executes the tool logic by preparing an ETH transfer transaction via ethersService.
    // Prepare Transaction tool (ETH transfers) server.tool( "prepareTransaction", "Prepare a basic ETH transfer transaction for signing. Returns transaction data that can be signed and broadcast.", { toAddress: z.string().regex(/^0x[a-fA-F0-9]{40}$/).describe( "The Ethereum address to send ETH to" ), value: z.string().describe( "The amount to send in ETH (e.g., '1.0', '0.5')" ), fromAddress: z.string().regex(/^0x[a-fA-F0-9]{40}$/).describe( "The Ethereum address sending the ETH" ), provider: z.string().optional().describe(PROVIDER_DESCRIPTION), chainId: z.number().optional().describe( "Optional. The chain ID to use." ), gasLimit: z.string().optional().describe( "Optional. The gas limit for the transaction" ), gasPrice: z.string().optional().describe( "Optional. The gas price (in gwei) for legacy transactions" ), maxFeePerGas: z.string().optional().describe( "Optional. The maximum fee per gas (in gwei) for EIP-1559 transactions" ), maxPriorityFeePerGas: z.string().optional().describe( "Optional. The maximum priority fee per gas (in gwei) for EIP-1559 transactions" ) }, async ({ toAddress, value, fromAddress, provider, chainId, gasLimit, gasPrice, maxFeePerGas, maxPriorityFeePerGas }) => { try { // Prepare gas options const options = { gasLimit, gasPrice, maxFeePerGas, maxPriorityFeePerGas }; const txRequest = await ethersService.prepareTransaction( toAddress, value, fromAddress, provider, chainId, options ); return { content: [{ type: "text", text: `ETH Transfer Transaction Prepared: From: ${fromAddress} To: ${toAddress} Amount: ${value} ETH Transaction Data: ${JSON.stringify({ to: txRequest.to, value: txRequest.value?.toString(), from: txRequest.from, gasLimit: txRequest.gasLimit?.toString(), gasPrice: txRequest.gasPrice?.toString(), maxFeePerGas: txRequest.maxFeePerGas?.toString(), maxPriorityFeePerGas: txRequest.maxPriorityFeePerGas?.toString(), chainId: txRequest.chainId }, null, 2)} This transaction is ready to be signed and broadcast.` }] }; } catch (error) { return { isError: true, content: [{ type: "text", text: `Error preparing transaction: ${error instanceof Error ? error.message : String(error)}` }] }; } } );
  • Handler function for the 'prepareTransaction' tool. It constructs gas options and calls ethersService.prepareTransaction to generate the unsigned transaction data, then formats and returns it.
    async ({ toAddress, value, fromAddress, provider, chainId, gasLimit, gasPrice, maxFeePerGas, maxPriorityFeePerGas }) => { try { // Prepare gas options const options = { gasLimit, gasPrice, maxFeePerGas, maxPriorityFeePerGas }; const txRequest = await ethersService.prepareTransaction( toAddress, value, fromAddress, provider, chainId, options ); return { content: [{ type: "text", text: `ETH Transfer Transaction Prepared: From: ${fromAddress} To: ${toAddress} Amount: ${value} ETH Transaction Data: ${JSON.stringify({ to: txRequest.to, value: txRequest.value?.toString(), from: txRequest.from, gasLimit: txRequest.gasLimit?.toString(), gasPrice: txRequest.gasPrice?.toString(), maxFeePerGas: txRequest.maxFeePerGas?.toString(), maxPriorityFeePerGas: txRequest.maxPriorityFeePerGas?.toString(), chainId: txRequest.chainId }, null, 2)} This transaction is ready to be signed and broadcast.` }] }; } catch (error) { return { isError: true, content: [{ type: "text", text: `Error preparing transaction: ${error instanceof Error ? error.message : String(error)}` }] }; } }
  • Input schema for the 'prepareTransaction' tool defined using Zod validators for parameters like toAddress, value, fromAddress, provider, chainId, and gas options.
    { toAddress: z.string().regex(/^0x[a-fA-F0-9]{40}$/).describe( "The Ethereum address to send ETH to" ), value: z.string().describe( "The amount to send in ETH (e.g., '1.0', '0.5')" ), fromAddress: z.string().regex(/^0x[a-fA-F0-9]{40}$/).describe( "The Ethereum address sending the ETH" ), provider: z.string().optional().describe(PROVIDER_DESCRIPTION), chainId: z.number().optional().describe( "Optional. The chain ID to use." ), gasLimit: z.string().optional().describe( "Optional. The gas limit for the transaction" ), gasPrice: z.string().optional().describe( "Optional. The gas price (in gwei) for legacy transactions" ), maxFeePerGas: z.string().optional().describe( "Optional. The maximum fee per gas (in gwei) for EIP-1559 transactions" ), maxPriorityFeePerGas: z.string().optional().describe( "Optional. The maximum priority fee per gas (in gwei) for EIP-1559 transactions" ) },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/crazyrabbitLTC/mcp-ethers-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server