Skip to main content
Glama

encode_calldata

Encodes EVM function calls into calldata hex for smart contract interactions. Provide ABI fragments, function name, and arguments to generate callable data and function selectors.

Instructions

Encode EVM function call into calldata hex. Provide ABI fragment array, function name, and arguments. Returns hex calldata and function selector for use with call_contract.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
abiYesABI fragment array for the function (JSON array of objects)
functionNameYesFunction name to encode (e.g., "transfer", "approve")
argsNoFunction arguments array (e.g., ["0xAddress", "1000000"]). Omit for zero-arg functions.
wallet_idNoTarget wallet ID. Required for multi-wallet sessions; auto-resolved when session has a single wallet.

Implementation Reference

  • The actual handler function for the `encode_calldata` tool, which performs an API call to encode the calldata.
    async (args) => {
      const body: Record<string, unknown> = {
        abi: args.abi,
        functionName: args.functionName,
        args: args.args ?? [],
      };
      if (args.wallet_id) body.walletId = args.wallet_id;
      const result = await apiClient.post('/v1/utils/encode-calldata', body);
      return toToolResult(result);
    },
  • Input schema validation for the `encode_calldata` tool using Zod.
    {
      abi: z.array(z.record(z.unknown())).describe('ABI fragment array for the function (JSON array of objects)'),
      functionName: z.string().describe('Function name to encode (e.g., "transfer", "approve")'),
      args: z.array(z.any()).optional().describe('Function arguments array (e.g., ["0xAddress", "1000000"]). Omit for zero-arg functions.'),
      wallet_id: z.string().optional().describe('Target wallet ID. Required for multi-wallet sessions; auto-resolved when session has a single wallet.'),
    },
  • Registration function that defines the `encode_calldata` MCP tool.
    export function registerEncodeCalldata(
      server: McpServer,
      apiClient: ApiClient,
      walletContext?: WalletContext,
    ): void {
      server.tool(
        'encode_calldata',
        withWalletPrefix(
          'Encode EVM function call into calldata hex. Provide ABI fragment array, function name, and arguments. Returns hex calldata and function selector for use with call_contract.',
          walletContext?.walletName,
        ),
        {
          abi: z.array(z.record(z.unknown())).describe('ABI fragment array for the function (JSON array of objects)'),
          functionName: z.string().describe('Function name to encode (e.g., "transfer", "approve")'),
          args: z.array(z.any()).optional().describe('Function arguments array (e.g., ["0xAddress", "1000000"]). Omit for zero-arg functions.'),
          wallet_id: z.string().optional().describe('Target wallet ID. Required for multi-wallet sessions; auto-resolved when session has a single wallet.'),
        },
        async (args) => {
          const body: Record<string, unknown> = {
            abi: args.abi,
            functionName: args.functionName,
            args: args.args ?? [],
          };
          if (args.wallet_id) body.walletId = args.wallet_id;
          const result = await apiClient.post('/v1/utils/encode-calldata', body);
          return toToolResult(result);
        },
      );
    }

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/minhoyoo-iotrust/WAIaaS'

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