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"
      )
    },
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It discloses that the tool prepares transaction data for signing and broadcasting, which implies it's a read-only preparation step (not executing the transaction). However, it doesn't mention permissions, rate limits, network dependencies, or error handling, leaving behavioral gaps for a tool with 9 parameters.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with the core purpose in the first sentence and adds output details in the second. It's efficient with no wasted words, though it could be slightly more structured by explicitly separating purpose from output or usage notes.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity (9 parameters, no annotations, no output schema), the description is minimally adequate. It covers the basic purpose and output but lacks details on behavioral traits, error cases, or how the prepared data should be used with sibling tools like signMessage or sendSignedTransaction. For a preparation tool in a blockchain context, more guidance would be helpful.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds no additional parameter semantics beyond what's in the schema, such as explaining interactions between parameters (e.g., gasPrice vs. maxFeePerGas) or default behaviors. Baseline 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('prepare a basic ETH transfer transaction for signing') and the resource ('ETH transfer transaction'), distinguishing it from sibling tools like prepareContractTransaction or prepareERC20Transfer. It explicitly mentions the output ('Returns transaction data that can be signed and broadcast'), making the purpose unambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for ETH transfers but doesn't explicitly state when to use this tool versus alternatives like prepareContractTransaction or sendTransaction. It mentions the output is for signing and broadcasting, which provides some context, but lacks explicit guidance on prerequisites, error conditions, or comparisons to sibling tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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