Skip to main content
Glama

call_contract

Execute smart contract functions on EVM or Solana blockchains using whitelisted contracts. Send transactions with specified parameters like contract address, calldata, and network details for secure blockchain interactions.

Instructions

Call a whitelisted smart contract. Requires CONTRACT_WHITELIST policy. For EVM: provide calldata (hex). For Solana: provide programId + instructionData + accounts.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
toYesContract address
calldataNoHex-encoded calldata (EVM)
abiNoABI fragment for decoding (EVM)
valueNoNative token value in smallest units (wei). Example: "1000000000000000000" = 1 ETH
programIdNoProgram ID (Solana)
instructionDataNoBase64-encoded instruction data (Solana)
accountsNoAccount metas (Solana)
networkNoTarget network (e.g., "polygon-mainnet" or CAIP-2 "eip155:137"). Required for EVM wallets; auto-resolved for Solana.
wallet_idNoTarget wallet ID. Required for multi-wallet sessions; auto-resolved when session has a single wallet.
gas_conditionNoGas price condition for deferred execution. At least one of max_gas_price or max_priority_fee required.

Implementation Reference

  • The handler function within the call_contract tool, which formats the request body and calls the /v1/transactions/send API endpoint.
    async (args) => {
      const body: Record<string, unknown> = { type: 'CONTRACT_CALL', to: args.to };
      if (args.calldata !== undefined) body.calldata = args.calldata;
      if (args.abi !== undefined) body.abi = args.abi;
      if (args.value !== undefined) body.value = args.value;
      if (args.programId !== undefined) body.programId = args.programId;
      if (args.instructionData !== undefined) body.instructionData = args.instructionData;
      if (args.accounts !== undefined) body.accounts = args.accounts;
      if (args.network !== undefined) body.network = args.network;
      if (args.wallet_id) body.walletId = args.wallet_id;
      if (args.gas_condition) {
        body.gasCondition = {
          maxGasPrice: args.gas_condition.max_gas_price,
          maxPriorityFee: args.gas_condition.max_priority_fee,
          timeout: args.gas_condition.timeout,
        };
      }
      const result = await apiClient.post('/v1/transactions/send', body);
      return toToolResult(result);
    },
  • The Zod schema defining the input parameters for the call_contract tool.
    {
      to: z.string().describe('Contract address'),
      calldata: z.string().optional().describe('Hex-encoded calldata (EVM)'),
      abi: z.array(z.record(z.unknown())).optional().describe('ABI fragment for decoding (EVM)'),
      value: z.string().optional().describe('Native token value in smallest units (wei). Example: "1000000000000000000" = 1 ETH'),
      programId: z.string().optional().describe('Program ID (Solana)'),
      instructionData: z.string().optional().describe('Base64-encoded instruction data (Solana)'),
      accounts: z.array(z.object({
        pubkey: z.string(),
        isSigner: z.boolean(),
        isWritable: z.boolean(),
      })).optional().describe('Account metas (Solana)'),
      network: z.string().optional().describe('Target network (e.g., "polygon-mainnet" or CAIP-2 "eip155:137"). Required for EVM wallets; auto-resolved for Solana.'),
      wallet_id: z.string().optional().describe('Target wallet ID. Required for multi-wallet sessions; auto-resolved when session has a single wallet.'),
      gas_condition: z.object({
        max_gas_price: z.string().optional().describe('Max gas price in wei (EVM baseFee+priorityFee)'),
        max_priority_fee: z.string().optional().describe('Max priority fee in wei (EVM) or micro-lamports (Solana)'),
        timeout: z.number().optional().describe('Max wait time in seconds (60-86400)'),
      }).optional().describe('Gas price condition for deferred execution. At least one of max_gas_price or max_priority_fee required.'),
    },
  • The registerCallContract function that registers the call_contract tool with the MCP server.
    export function registerCallContract(server: McpServer, apiClient: ApiClient, walletContext?: WalletContext): void {
      server.tool(
        'call_contract',
        withWalletPrefix('Call a whitelisted smart contract. Requires CONTRACT_WHITELIST policy. For EVM: provide calldata (hex). For Solana: provide programId + instructionData + accounts.', walletContext?.walletName),
        {
          to: z.string().describe('Contract address'),
          calldata: z.string().optional().describe('Hex-encoded calldata (EVM)'),
          abi: z.array(z.record(z.unknown())).optional().describe('ABI fragment for decoding (EVM)'),
          value: z.string().optional().describe('Native token value in smallest units (wei). Example: "1000000000000000000" = 1 ETH'),
          programId: z.string().optional().describe('Program ID (Solana)'),
          instructionData: z.string().optional().describe('Base64-encoded instruction data (Solana)'),
          accounts: z.array(z.object({
            pubkey: z.string(),
            isSigner: z.boolean(),
            isWritable: z.boolean(),
          })).optional().describe('Account metas (Solana)'),
          network: z.string().optional().describe('Target network (e.g., "polygon-mainnet" or CAIP-2 "eip155:137"). Required for EVM wallets; auto-resolved for Solana.'),
          wallet_id: z.string().optional().describe('Target wallet ID. Required for multi-wallet sessions; auto-resolved when session has a single wallet.'),
          gas_condition: z.object({
            max_gas_price: z.string().optional().describe('Max gas price in wei (EVM baseFee+priorityFee)'),
            max_priority_fee: z.string().optional().describe('Max priority fee in wei (EVM) or micro-lamports (Solana)'),
            timeout: z.number().optional().describe('Max wait time in seconds (60-86400)'),
          }).optional().describe('Gas price condition for deferred execution. At least one of max_gas_price or max_priority_fee required.'),
        },
        async (args) => {
          const body: Record<string, unknown> = { type: 'CONTRACT_CALL', to: args.to };
          if (args.calldata !== undefined) body.calldata = args.calldata;
          if (args.abi !== undefined) body.abi = args.abi;
          if (args.value !== undefined) body.value = args.value;
          if (args.programId !== undefined) body.programId = args.programId;
          if (args.instructionData !== undefined) body.instructionData = args.instructionData;
          if (args.accounts !== undefined) body.accounts = args.accounts;
          if (args.network !== undefined) body.network = args.network;
          if (args.wallet_id) body.walletId = args.wallet_id;
          if (args.gas_condition) {
            body.gasCondition = {
              maxGasPrice: args.gas_condition.max_gas_price,
              maxPriorityFee: args.gas_condition.max_priority_fee,
              timeout: args.gas_condition.timeout,
            };
          }
          const result = await apiClient.post('/v1/transactions/send', 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