Skip to main content
Glama

prepareERC20Transfer

Prepare ERC20 token transfer transactions for signing and broadcasting. Specify token contract, recipient, amount, and sender addresses to generate transaction data.

Instructions

Prepare an ERC20 token transfer transaction for signing. Returns transaction data that can be signed and broadcast.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contractAddressYesThe address of the ERC20 token contract
tokenAddressNoDEPRECATED: Use contractAddress instead. The address of the ERC20 token contract
recipientAddressYesThe Ethereum address to receive the tokens
amountYesThe amount of tokens to transfer (can be decimal, e.g. '1.5')
fromAddressYesThe Ethereum address sending the tokens
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. If provided with a named network and they don't match, the RPC's chain ID will be used.
gasLimitNo
gasPriceNo
maxFeePerGasNo
maxPriorityFeePerGasNo

Implementation Reference

  • Registration of the 'prepareERC20Transfer' MCP tool including input schema definition and complete handler implementation. The handler prepares an unsigned ERC20 transfer transaction.
      server.tool(
        "prepareERC20Transfer",
        "Prepare an ERC20 token transfer transaction for signing. Returns transaction data that can be signed and broadcast.",
        {
          contractAddress: contractAddressSchema,
          tokenAddress: tokenAddressSchema.optional(),  // Deprecated
          recipientAddress: z.string().describe(
            "The Ethereum address to receive the tokens"
          ),
          amount: amountSchema,
          fromAddress: z.string().describe(
            "The Ethereum address sending the tokens"
          ),
          provider: providerSchema,
          chainId: chainIdSchema,
          gasLimit: z.string().optional(),
          gasPrice: z.string().optional(),
          maxFeePerGas: z.string().optional(),
          maxPriorityFeePerGas: z.string().optional()
        },
        async (params) => {
          // Map deprecated parameters
          const mapped = mapParameters(params);
          
          try {
            const contractAddr = mapped.contractAddress || params.tokenAddress;
            if (!contractAddr) {
              throw new Error('Either contractAddress or tokenAddress must be provided');
            }
    
            // Get token info for display
            const tokenInfo = await ethersService.getERC20TokenInfo(
              contractAddr,
              mapped.provider,
              mapped.chainId
            );
            
            // Prepare gas options
            const options = {
              gasLimit: params.gasLimit,
              gasPrice: params.gasPrice,
              maxFeePerGas: params.maxFeePerGas,
              maxPriorityFeePerGas: params.maxPriorityFeePerGas
            };
            
            const txRequest = await ethersService.prepareERC20Transfer(
              contractAddr,
              mapped.recipientAddress,
              mapped.amount,
              mapped.fromAddress,
              mapped.provider,
              mapped.chainId,
              options
            );
            
            return {
              content: [{ 
                type: "text", 
                text: `ERC20 Transfer Transaction Prepared:
    
    Token: ${tokenInfo.name} (${tokenInfo.symbol})
    From: ${mapped.fromAddress}
    To: ${mapped.recipientAddress}
    Amount: ${mapped.amount} ${tokenInfo.symbol}
    
    Transaction Data:
    ${JSON.stringify({
      to: txRequest.to,
      data: txRequest.data,
      value: txRequest.value || "0",
      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 transfer transaction: ${error instanceof Error ? error.message : String(error)}`
              }]
            };
          }
        }
      );
  • Core handler logic for executing the prepareERC20Transfer tool: parameter mapping, validation, token info retrieval, transaction preparation via ethersService, and response formatting.
        async (params) => {
          // Map deprecated parameters
          const mapped = mapParameters(params);
          
          try {
            const contractAddr = mapped.contractAddress || params.tokenAddress;
            if (!contractAddr) {
              throw new Error('Either contractAddress or tokenAddress must be provided');
            }
    
            // Get token info for display
            const tokenInfo = await ethersService.getERC20TokenInfo(
              contractAddr,
              mapped.provider,
              mapped.chainId
            );
            
            // Prepare gas options
            const options = {
              gasLimit: params.gasLimit,
              gasPrice: params.gasPrice,
              maxFeePerGas: params.maxFeePerGas,
              maxPriorityFeePerGas: params.maxPriorityFeePerGas
            };
            
            const txRequest = await ethersService.prepareERC20Transfer(
              contractAddr,
              mapped.recipientAddress,
              mapped.amount,
              mapped.fromAddress,
              mapped.provider,
              mapped.chainId,
              options
            );
            
            return {
              content: [{ 
                type: "text", 
                text: `ERC20 Transfer Transaction Prepared:
    
    Token: ${tokenInfo.name} (${tokenInfo.symbol})
    From: ${mapped.fromAddress}
    To: ${mapped.recipientAddress}
    Amount: ${mapped.amount} ${tokenInfo.symbol}
    
    Transaction Data:
    ${JSON.stringify({
      to: txRequest.to,
      data: txRequest.data,
      value: txRequest.value || "0",
      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 transfer transaction: ${error instanceof Error ? error.message : String(error)}`
              }]
            };
          }
        }
  • Input schema definition for the prepareERC20Transfer tool using Zod schemas for validation including contract address, recipient, amount, from address, provider options, and gas parameters.
    {
      contractAddress: contractAddressSchema,
      tokenAddress: tokenAddressSchema.optional(),  // Deprecated
      recipientAddress: z.string().describe(
        "The Ethereum address to receive the tokens"
      ),
      amount: amountSchema,
      fromAddress: z.string().describe(
        "The Ethereum address sending the tokens"
      ),
      provider: providerSchema,
      chainId: chainIdSchema,
      gasLimit: z.string().optional(),
      gasPrice: z.string().optional(),
      maxFeePerGas: z.string().optional(),
      maxPriorityFeePerGas: z.string().optional()
    },
  • Top-level registration call for all ERC20 tools including prepareERC20Transfer via registerERC20Tools.
    registerERC20Tools(server, ethersService);
Behavior2/5

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

With no annotations provided, the description carries full burden but lacks critical behavioral details. It doesn't disclose that this is a read-only preparation step (not a broadcast), doesn't mention gas estimation or network requirements, and omits error conditions like insufficient balance. For a complex 11-parameter tool with financial implications, this is inadequate.

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

Conciseness5/5

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

The description is perfectly concise with two sentences that front-load the core purpose and output. Every word earns its place, with no redundancy or unnecessary elaboration, making it easy to parse quickly.

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

Completeness2/5

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

For a complex financial tool with 11 parameters, no annotations, and no output schema, the description is insufficient. It doesn't explain the transaction lifecycle, error handling, or relationship to signing/broadcasting tools. Given the high-stakes nature of token transfers, more contextual guidance is needed.

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

Parameters4/5

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

The description adds value beyond the 64% schema coverage by clarifying the output purpose ('transaction data that can be signed and broadcast'), which helps interpret parameters like gas fields. While it doesn't detail individual parameters, the high-level context compensates for schema gaps, especially given the 11 parameters involved.

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 an ERC20 token transfer transaction for signing') and resource ('ERC20 token'), distinguishing it from sibling tools like prepareERC20Approval or prepareTransaction. It precisely defines the tool's function without ambiguity.

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 by stating it 'returns transaction data that can be signed and broadcast,' suggesting it's part of a multi-step process. However, it doesn't explicitly guide when to use this tool versus alternatives like prepareTransaction or sendTransaction, nor does it mention prerequisites like wallet loading.

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