Skip to main content
Glama
lienhage
by lienhage

abi-decode

Decode ABI-encoded data by specifying parameter types and input hexadecimal data, simplifying Ethereum blockchain interactions for developers and users.

Instructions

decode abi encoded data

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dataYeshexadecimal data to decode
typesYesparameter types array, e.g. ['uint256', 'address', 'bool']

Implementation Reference

  • Handler function that cleans input data, decodes using ethers.AbiCoder.decode(types, data), formats decoded values, and returns formatted text response or error.
    async ({ types, data }) => { try { const cleanData = data.startsWith('0x') ? data : `0x${data}`; const decoded = ethers.AbiCoder.defaultAbiCoder().decode(types, cleanData); const decodedValues = types.map((type, index) => { const value = decoded[index]; return ` ${type}: ${this.formatDecodedValue(value, type)}`; }).join('\n'); return { content: [{ type: "text", text: `abi decode result:\n\n📊 original data: ${cleanData}\n📋 parameter types: (${types.join(',')})\n\n📝 decoded values:\n${decodedValues}` }] }; } catch (error) { return { content: [{ type: "text", text: `error: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } }
  • Zod schema for tool inputs: array of ABI types and hex data string.
    inputSchema: { types: z.array(z.string()).describe("parameter types array, e.g. ['uint256', 'address', 'bool']"), data: z.string().describe("hexadecimal data to decode") }
  • Direct registration of the 'abi-decode' tool on the MCP server with schema and handler.
    server.registerTool( "abi-decode", { title: "abi decode", description: "decode abi encoded data", inputSchema: { types: z.array(z.string()).describe("parameter types array, e.g. ['uint256', 'address', 'bool']"), data: z.string().describe("hexadecimal data to decode") } }, async ({ types, data }) => { try { const cleanData = data.startsWith('0x') ? data : `0x${data}`; const decoded = ethers.AbiCoder.defaultAbiCoder().decode(types, cleanData); const decodedValues = types.map((type, index) => { const value = decoded[index]; return ` ${type}: ${this.formatDecodedValue(value, type)}`; }).join('\n'); return { content: [{ type: "text", text: `abi decode result:\n\n📊 original data: ${cleanData}\n📋 parameter types: (${types.join(',')})\n\n📝 decoded values:\n${decodedValues}` }] }; } catch (error) { return { content: [{ type: "text", text: `error: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } );
  • Helper method used by the handler to format decoded values for display based on ABI type.
    private formatDecodedValue(value: any, type: string): string { if (typeof value === 'bigint') { return value.toString(); } if (type === 'address') { return value.toString(); } if (type === 'bool') { return value ? 'true' : 'false'; } if (type.startsWith('bytes')) { return value.toString(); } if (typeof value === 'string') { return `"${value}"`; } return String(value); }
  • Registration call in CastCommands that triggers abi-encoder tool registrations including abi-decode.
    this.abiEncoder.registerWithServer(server);

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/lienhage/blockchain-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server