get_abi
Retrieve the ABI (Application Binary Interface) for any smart contract on a specified blockchain network using the Bankless Onchain MCP Server.
Instructions
Gets the ABI for a given contract on a specific network
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| contract | Yes | The contract address | |
| network | Yes | The blockchain network (e.g., "ethereum", "base") |
Implementation Reference
- src/operations/contracts.ts:268-314 (handler)The core handler function that performs an authenticated GET request to the Bankless API to retrieve the ABI for the specified contract on the given network.export async function getAbi( network: string, contract: string ): Promise<ContractAbiResponse> { const token = process.env.BANKLESS_API_TOKEN; if (!token) { throw new BanklessAuthenticationError('BANKLESS_API_TOKEN environment variable is not set'); } const endpoint = `${BASE_URL}/chains/${network}/get_abi/${contract}`; try { const response = await axios.get( endpoint, { headers: { 'Content-Type': 'application/json', 'X-BANKLESS-TOKEN': `${token}` } } ); return response.data; } catch (error) { if (axios.isAxiosError(error)) { const statusCode = error.response?.status || 'unknown'; const errorMessage = error.response?.data?.message || error.message; if (statusCode === 401 || statusCode === 403) { throw new BanklessAuthenticationError(`Authentication Failed: ${errorMessage}`); } else if (statusCode === 404) { throw new BanklessResourceNotFoundError(`Not Found: ${errorMessage}`); } else if (statusCode === 422) { throw new BanklessValidationError(`Validation Error: ${errorMessage}`, error.response?.data); } else if (statusCode === 429) { // Extract reset timestamp or default to 60 seconds from now const resetAt = new Date(); resetAt.setSeconds(resetAt.getSeconds() + 60); throw new BanklessRateLimitError(`Rate Limit Exceeded: ${errorMessage}`, resetAt); } throw new Error(`Bankless API Error (${statusCode}): ${errorMessage}`); } throw new Error(`Failed to get contract ABI: ${error instanceof Error ? error.message : String(error)}`); } }
- src/operations/contracts.ts:75-78 (schema)Zod schema validating the input parameters for the get_abi tool: network and contract address.export const GetAbiSchema = z.object({ network: z.string().describe('The blockchain network (e.g., "ethereum", "base")'), contract: z.string().describe('The contract address'), });
- src/index.ts:87-91 (registration)MCP tool registration defining the name, description, and input schema for the get_abi tool.{ name: "get_abi", description: "Gets the ABI for a given contract on a specific network", inputSchema: zodToJsonSchema(contracts.GetAbiSchema), },
- src/index.ts:170-178 (handler)Dispatch handler in the main CallToolRequest handler that parses arguments, calls the getAbi function, and formats the response.case "get_abi": { const args = contracts.GetAbiSchema.parse(request.params.arguments); const result = await contracts.getAbi( args.network, args.contract ); return { content: [{type: "text", text: JSON.stringify(result, null, 2)}], };