Skip to main content
Glama

transfer_erc20

Send ERC20 tokens to a specified address using a private key on Ethereum and EVM-compatible networks. Specify token contract, recipient, and amount to execute the transfer.

Instructions

Transfer ERC20 tokens to another address

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
amountYesThe amount of tokens to send (in token units, e.g., '10' for 10 tokens)
networkNoNetwork name (e.g., 'ethereum', 'optimism', 'arbitrum', 'base', etc.) or chain ID. Supports all EVM-compatible networks. Defaults to Ethereum mainnet.
privateKeyYesPrivate key of the sending account (this is used for signing and is never stored)
toAddressYesThe recipient address
tokenAddressYesThe address of the ERC20 token contract

Implementation Reference

  • The MCP tool handler for 'transfer_erc20' that retrieves the configured wallet's private key, calls the transferERC20 service helper, and returns the transaction details including txHash and token info.
    async ({ tokenAddress, to, amount, network = "ethereum" }) => {
      try {
        const privateKey = getConfiguredPrivateKey();
        const senderAddress = getWalletAddressFromKey();
        const result = await services.transferERC20(tokenAddress as Address, to as Address, amount, privateKey, network);
        return {
          content: [{
            type: "text",
            text: JSON.stringify({
              network,
              tokenAddress,
              from: senderAddress,
              to,
              amount: result.amount.formatted,
              symbol: result.token.symbol,
              decimals: result.token.decimals,
              txHash: result.txHash,
              message: "Transaction sent. Use get_transaction_receipt to check confirmation."
            }, null, 2)
          }]
        };
      } catch (error) {
        return {
          content: [{ type: "text", text: `Error transferring ERC20 tokens: ${error instanceof Error ? error.message : String(error)}` }],
          isError: true
        };
      }
    }
  • Zod input schema defining parameters for the transfer_erc20 tool: tokenAddress (string), to (string), amount (string), network (optional string).
    inputSchema: {
      tokenAddress: z.string().describe("The ERC20 token contract address"),
      to: z.string().describe("Recipient address or ENS name"),
      amount: z.string().describe("Amount to send (in token units, accounting for decimals)"),
      network: z.string().optional().describe("Network name or chain ID. Defaults to Ethereum mainnet.")
    },
  • Registration of the 'transfer_erc20' tool with the MCP server, including description, input schema, and annotations indicating it's a destructive write operation.
    server.registerTool(
      "transfer_erc20",
      {
        description: "Transfer ERC20 tokens to an address. Uses the configured wallet.",
        inputSchema: {
          tokenAddress: z.string().describe("The ERC20 token contract address"),
          to: z.string().describe("Recipient address or ENS name"),
          amount: z.string().describe("Amount to send (in token units, accounting for decimals)"),
          network: z.string().optional().describe("Network name or chain ID. Defaults to Ethereum mainnet.")
        },
        annotations: {
          title: "Transfer ERC20 Tokens",
          readOnlyHint: false,
          destructiveHint: true,
          idempotentHint: false,
          openWorldHint: true
        }
      },
  • Core helper function implementing ERC20 transfer logic: resolves ENS names, fetches token decimals and symbol, parses amount using parseUnits, and executes the transfer transaction via viem's walletClient.writeContract.
    export async function transferERC20(
      tokenAddressOrEns: string,
      toAddressOrEns: string,
      amount: string,
      privateKey: string | `0x${string}`,
      network: string = 'ethereum'
    ): Promise<{
      txHash: Hash;
      amount: {
        raw: bigint;
        formatted: string;
      };
      token: {
        symbol: string;
        decimals: number;
      };
    }> {
      // Resolve ENS names to addresses if needed
      const tokenAddress = await resolveAddress(tokenAddressOrEns, network) as Address;
      const toAddress = await resolveAddress(toAddressOrEns, network) as Address;
      
      // Ensure the private key has 0x prefix
      const formattedKey = typeof privateKey === 'string' && !privateKey.startsWith('0x')
        ? `0x${privateKey}` as `0x${string}`
        : privateKey as `0x${string}`;
      
      // Get token details
      const publicClient = getPublicClient(network);
      const contract = getContract({
        address: tokenAddress,
        abi: erc20TransferAbi,
        client: publicClient,
      });
      
      // Get token decimals and symbol
      const decimals = await contract.read.decimals();
      const symbol = await contract.read.symbol();
      
      // Parse the amount with the correct number of decimals
      const rawAmount = parseUnits(amount, decimals);
      
      // Create wallet client for sending the transaction
      const walletClient = getWalletClient(formattedKey, network);
      
      // Send the transaction
      const hash = await walletClient.writeContract({
        address: tokenAddress,
        abi: erc20TransferAbi,
        functionName: 'transfer',
        args: [toAddress, rawAmount],
        account: walletClient.account!,
        chain: walletClient.chain
      });
      
      return {
        txHash: hash,
        amount: {
          raw: rawAmount,
          formatted: amount
        },
        token: {
          symbol,
          decimals
        }
      };
    }
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 only states the basic action. It doesn't disclose critical behavioral traits: this is a write/mutation operation (implied by 'transfer'), requires signing with a private key (hinted in schema but not in description), has security implications (private key handling), or potential transaction costs (gas fees).

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?

Extremely concise single sentence with zero wasted words. It's front-loaded with the core action and resource, 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 transaction tool with 5 parameters, no annotations, and no output schema, the description is inadequate. It doesn't explain what happens after transfer (success/failure states), return values, error conditions, or security considerations, leaving significant gaps for agent understanding.

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%, providing detailed parameter documentation. The description adds no additional parameter semantics beyond what's in the schema, so it meets the baseline of 3 where the schema does the heavy lifting.

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

Purpose4/5

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

The description clearly states the action ('transfer') and resource ('ERC20 tokens'), specifying the destination ('to another address'). It distinguishes from siblings like 'transfer_eth' or 'transfer_nft' by specifying ERC20 tokens, but doesn't explicitly differentiate from 'transfer_token' which might be similar.

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

Usage Guidelines2/5

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

No guidance on when to use this tool versus alternatives like 'transfer_eth' or 'transfer_token'. The description lacks context about prerequisites (e.g., needing a private key) or exclusions, leaving the agent to infer usage from parameters alone.

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

Related 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/mcpdotdirect/evm-mcp-server'

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