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
| Variable | Description | Required |
|---|---|---|
WALLET_PRIVATE_KEY | Private key for transaction signing | For write functions |
CONTRACT_ABI | JSON string of the contract's ABI | Yes |
CONTRACT_ADDRESS | Deployed contract address | Yes |
CONTRACT_NAME | Friendly name for tool prefixes | Optional (defaults to "CONTRACT") |
CHAIN_ID | Blockchain network chain ID | Optional (defaults to Fraxtal - 252) |
RPC_URL | Custom RPC endpoint URL | Optional |
Usage Examples
ERC20 Token Contract
- Check balance:
ERC20_BALANCE_OFwith address parameter - Transfer tokens:
ERC20_TRANSFERwith recipient and amount - Check allowances:
ERC20_ALLOWANCEwith owner and spender - Approve spending:
ERC20_APPROVEwith spender and amount
NFT Contract (ERC721)
- Check ownership:
NFT_OWNER_OFwith token ID - Transfer NFT:
NFT_TRANSFER_FROMwith from, to, and token ID - Mint token:
NFT_MINTwith 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]"