get_token_info
Query detailed information about an ERC20 token on the Rootstock blockchain using its contract address.
Instructions
Get information about an ERC20 token
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tokenAddress | Yes | ERC20 token contract address |
Input Schema (JSON Schema)
{
"properties": {
"tokenAddress": {
"description": "ERC20 token contract address",
"type": "string"
}
},
"required": [
"tokenAddress"
],
"type": "object"
}
Implementation Reference
- src/index.ts:881-895 (handler)Primary MCP tool handler for 'get_token_info'. Calls rootstockClient.getTokenInfo and formats the response as text content.private async handleGetTokenInfo(params: GetTokenInfoParams) { try { const result = await this.rootstockClient.getTokenInfo(params.tokenAddress); return { content: [ { type: 'text', text: `Token Information:\n\nAddress: ${result.address}\nName: ${result.name}\nSymbol: ${result.symbol}\nDecimals: ${result.decimals}\nTotal Supply: ${result.totalSupply}${result.owner ? `\nOwner: ${result.owner}` : ''}`, }, ], }; } catch (error) { throw new Error(`Failed to get token info: ${error}`); } }
- src/index.ts:445-457 (registration)Tool registration in getAvailableTools() including name, description, and input schema for list tools request.name: 'get_token_info', description: 'Get information about an ERC20 token', inputSchema: { type: 'object', properties: { tokenAddress: { type: 'string', description: 'ERC20 token contract address', }, }, required: ['tokenAddress'], }, },
- src/types.ts:194-196 (schema)TypeScript interface defining input parameters for the get_token_info tool.export interface GetTokenInfoParams { tokenAddress: string; }
- src/rootstock-client.ts:494-540 (helper)Core helper method in RootstockClient that queries the ERC20 smart contract for token details using ethers.js: name, symbol, decimals, totalSupply, and owner if available.async getTokenInfo(tokenAddress: string): Promise<{ address: string; name: string; symbol: string; decimals: number; totalSupply: string; owner?: string; }> { try { const tokenContract = new ethers.Contract( tokenAddress, this.getStandardERC20ABI(), this.getProvider() ); const [name, symbol, decimals, totalSupply] = await Promise.all([ tokenContract.name(), tokenContract.symbol(), tokenContract.decimals(), tokenContract.totalSupply(), ]); let owner: string | undefined; try { // Try to get owner if it's a mintable token const mintableContract = new ethers.Contract( tokenAddress, this.getMintableERC20ABI(), this.getProvider() ); owner = await mintableContract.owner(); } catch { // Owner function doesn't exist, it's a standard token } return { address: tokenAddress, name, symbol, decimals: Number(decimals), totalSupply: ethers.formatUnits(totalSupply, decimals), owner, }; } catch (error) { throw new Error(`Failed to get token info: ${error}`); } }
- src/smithery-server.ts:587-624 (registration)Alternative tool registration and inline handler in Smithery-compatible server using Zod schema.server.tool( "get_token_info", "Get comprehensive ERC20 token information including name, symbol, decimals, supply, and owner", { tokenAddress: z.string().describe("ERC20 token contract address"), }, async ({ tokenAddress }) => { try { const result = await rootstockClient.getTokenInfo(tokenAddress); const explorerUrl = rootstockClient.getExplorerUrl(); return { content: [ { type: "text", text: `ERC20 Token Information:\n\n` + `Contract Address: ${result.address}\n` + `Name: ${result.name}\n` + `Symbol: ${result.symbol}\n` + `Decimals: ${result.decimals}\n` + `Total Supply: ${result.totalSupply}\n` + `Owner: ${result.owner || 'N/A'}\n\n` + `Contract Explorer: ${explorerUrl}/address/${result.address}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error getting token info: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } );