onchain-mcp
Bankless Onchain MCP Server: Blockchain data access for AI models via MCP.

onchain-mcp Solution Overview
The Bankless Onchain MCP Server is a crucial tool within the MCP ecosystem, acting as a bridge between AI models and on-chain blockchain data. As an MCP server, it empowers AI to access and interpret smart contract states, event logs, and transaction histories across various blockchain networks through the Bankless API.
This solution offers contract operations like reading contract state, fetching ABI, and retrieving source code. It also provides event operations such as fetching event logs and building event topics, alongside transaction operations for retrieving transaction history and information. By implementing the MCP protocol, it ensures a standardized and secure way for AI models to interact with decentralized data.
Developers benefit from its ability to seamlessly integrate blockchain insights into AI workflows, enabling applications like intelligent DeFi management, on-chain analytics, and automated smart contract auditing. The server supports standard input/output and HTTP/SSE for data transmission, facilitating easy integration with existing AI infrastructure. Its value lies in simplifying the complexities of blockchain interaction for AI, fostering innovation in decentralized AI applications.
onchain-mcp Key Capabilities
Read Contract State
The read_contract
function allows AI models to directly query the state of smart contracts on various blockchain networks. It takes the network name, contract address, method name, input parameters (with their types and values), and expected output types as input. The function then executes the specified method on the contract and returns the results with typed values. This enables AI models to understand and react to the current state of blockchain-based applications.
For example, an AI model could use read_contract
to determine the balance of a specific token held by an address. The model would specify the token's contract address, the "balanceOf" method, and the address to query as input. The function would return the token balance, allowing the AI to make decisions based on the user's holdings. This is crucial for DeFi applications where AI can automate trading strategies or provide personalized investment advice. The underlying implementation uses the Bankless API to interact with the blockchain network and retrieve the contract state.
Fetch Contract Events
The get_events
function enables AI models to retrieve historical event logs emitted by smart contracts. It requires the network name, contract addresses, a primary topic to filter events, and optional additional topics. This allows AI models to monitor specific activities or state changes within a smart contract. The function returns an array of event logs matching the specified filter criteria, providing detailed information about each event, including the block number, transaction hash, and event parameters.
For instance, an AI model could use get_events
to track all "Transfer" events for a specific ERC-20 token. By analyzing these events, the AI can monitor token flows, identify large transactions, and detect potential security threats. This is valuable for building fraud detection systems or creating real-time dashboards that visualize on-chain activity. The function leverages the Bankless API to query the blockchain's event logs and filter them based on the provided topics.
Build Event Topic Signature
The build_event_topic
function allows AI models to dynamically generate event topic signatures from an event's name and argument types. It takes the network name, event name (including argument types), and an array of argument types as input. The function then calculates the keccak256 hash of the event signature, which is used as the topic in event log filtering. This is essential for AI models that need to construct complex event queries or react to events with dynamically generated signatures.
For example, if an AI model needs to monitor a custom event with a specific set of parameters, it can use build_event_topic
to generate the correct topic hash. This hash can then be used in the get_events
function to retrieve the relevant event logs. This is particularly useful for interacting with complex smart contracts that emit events with non-standard signatures. The function uses standard cryptographic hashing algorithms to generate the event topic signature.
Integration Advantages
The onchain-mcp
offers seamless integration with AI models through the Model Context Protocol (MCP). By adhering to the MCP standard, it allows AI models to access on-chain data using a unified and standardized interface. This simplifies the process of connecting AI models to blockchain data sources, reducing the need for custom integrations. The server provides a consistent set of tools and data formats, enabling AI developers to focus on building intelligent applications rather than dealing with the complexities of blockchain interactions. Furthermore, the use of the Bankless API ensures reliable and efficient access to on-chain data across various blockchain networks.