TypeScriptADK-TS

MCP ABI

Smart contract ABI interactions for Ethereum-compatible blockchains

  • Package: @iqai/mcp-abi
  • Purpose: Smart contract ABI interactions for Ethereum-compatible blockchains

Usage with ADK TypeScript

import {McpAbi} from "@iqai/adk";

const toolset = McpAbi({
  env: {
    WALLET_PRIVATE_KEY: process.env.WALLET_PRIVATE_KEY,
    CONTRACT_ABI: process.env.CONTRACT_ABI,
    CONTRACT_ADDRESS: process.env.CONTRACT_ADDRESS,
    CONTRACT_NAME: "ERC20",
    CHAIN_ID: "252",
    RPC_URL: "https://rpc.frax.com"
  },
})

const tools = await toolset.getTools()
import {McpToolset} from "@iqai/adk";

const toolset = new McpToolset({
  name: "ABI MCP Client",
  description: "Client for smart contract ABI interactions",
  transport: {
    mode: "stdio",
    command: "pnpm",
    args: ["dlx", "@iqai/mcp-abi"],
    env: {
      WALLET_PRIVATE_KEY: process.env.WALLET_PRIVATE_KEY,
      CONTRACT_ABI: process.env.CONTRACT_ABI,
      CONTRACT_ADDRESS: process.env.CONTRACT_ADDRESS,
      CONTRACT_NAME: "ERC20",
      CHAIN_ID: "252",
      RPC_URL: "https://rpc.frax.com",
      PATH: process.env.PATH || "",
    },
  },
})

const tools = await toolset.getTools()
{
  "mcpServers": {
    "smart-contract-abi": {
      "command": "pnpm",
      "args": ["dlx", "@iqai/mcp-abi"],
      "env": {
        "WALLET_PRIVATE_KEY": "your_wallet_private_key_here",
        "CONTRACT_ABI": "[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]",
        "CONTRACT_ADDRESS": "0xaB195B090Cc60C1EFd4d1cEE94Bf441F5931C01b",
        "CONTRACT_NAME": "ERC20",
        "CHAIN_ID": "252",
        "RPC_URL": "https://rpc.frax.com"
      }
    }
  }
}

Features

  • Dynamically generates MCP tools based on contract ABI
  • Supports both read (view/pure) and write functions
  • Automatic tool naming with contract prefixes
  • Compatible with any Ethereum-compatible blockchain
  • Comprehensive error handling and transaction management

Available Tools

Remote MCP Endpoint

This MCP server is hosted remotely and tools are discovered dynamically at runtime. For the full list of available tools and endpoints, see the official CoinGecko MCP documentation.

Environment Variables

VariableDescriptionRequired
WALLET_PRIVATE_KEYPrivate key for transaction signingFor write functions
CONTRACT_ABIJSON string of the contract's ABIYes
CONTRACT_ADDRESSDeployed contract addressYes
CONTRACT_NAMEFriendly name for tool prefixesOptional (defaults to "CONTRACT")
CHAIN_IDBlockchain network chain IDOptional (defaults to Fraxtal - 252)
RPC_URLCustom RPC endpoint URLOptional

Usage Examples

ERC20 Token Contract

  • Check balance: ERC20_BALANCE_OF with address parameter
  • Transfer tokens: ERC20_TRANSFER with recipient and amount
  • Check allowances: ERC20_ALLOWANCE with owner and spender
  • Approve spending: ERC20_APPROVE with spender and amount

NFT Contract (ERC721)

  • Check ownership: NFT_OWNER_OF with token ID
  • Transfer NFT: NFT_TRANSFER_FROM with from, to, and token ID
  • Mint token: NFT_MINT with recipient and metadata

Response Examples

Read Function Response:

✅ Successfully called balanceOf
Result: "1000000000000000000"

Write Function Response:

✅ Successfully executed transfer
Transaction hash: 0x123abc...
You can view this transaction on the blockchain explorer.

Error Handling

Common Errors

The server provides comprehensive error handling for various blockchain interaction scenarios.

  • 🚨 Invalid function arguments - "❌ Error parsing arguments: [specific error]"
  • 🔄 Transaction failures - "❌ Error with [function]: [error message]"
  • 🔒 Access control errors - "❌ Error with [function]: execution reverted"
  • 🌐 Network errors - "❌ Error with [function]: network connection failed"
  • 💲 Insufficient funds - "❌ Error with [function]: insufficient funds for gas"
  • 📄 ABI parsing errors - "❌ Invalid ABI format: [specific error]"
  • 🏠 Contract address errors - "❌ Invalid contract address: [address]"