getTokenDetails
Retrieve token metadata including decimals for converting raw blockchain balances to human-readable values. Essential for displaying accurate token amounts from getAccountState() across multiple chains.
Instructions
Fetches information about a non-native token (ERC-20, TRC-20, SPL, etc.) - not the chain's native currency. CRITICAL: This provides the 'decimals' field needed to convert raw token amounts from getAccountState() to human-readable values. Always call this for each token when displaying balances: human_readable = raw_amount ÷ 10^token_decimals
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| chainId | Yes | ||
| tokenId | Yes |
Implementation Reference
- src/module.ts:272-286 (handler)The handler function that executes the getTokenDetails tool logic: makes an API request to fetch token details and returns the JSON-stringified response.async ({ chainId, tokenId }) => { const details = await makeApiRequest<GetTokenDetailsResponse>( `${ADAMIK_API_BASE_URL}/${chainId}/token/${tokenId}`, ADAMIK_API_KEY ); const text = JSON.stringify(details); return { content: [ { type: "text", text, }, ], }; }
- src/module.ts:261-287 (registration)Registration of the 'getTokenDetails' tool on the McpServer instance, specifying name, description, input schema, and handler function.server.tool( "getTokenDetails", [ "Fetches information about a non-native token (ERC-20, TRC-20, SPL, etc.) - not the chain's native currency.", "CRITICAL: This provides the 'decimals' field needed to convert raw token amounts from getAccountState() to human-readable values.", "Always call this for each token when displaying balances: human_readable = raw_amount ÷ 10^token_decimals", ].join(" "), { chainId: ChainIdSchema, tokenId: z.string(), }, async ({ chainId, tokenId }) => { const details = await makeApiRequest<GetTokenDetailsResponse>( `${ADAMIK_API_BASE_URL}/${chainId}/token/${tokenId}`, ADAMIK_API_KEY ); const text = JSON.stringify(details); return { content: [ { type: "text", text, }, ], }; } );
- src/schemas.ts:129-141 (schema)Zod schemas defining the structure of the GetTokenDetailsResponse (including TokenInfoSchema), used for type safety in the handler's API response.export const TokenInfoSchema = z.object({ type: TokenTypeSchema, id: z.string(), name: z.string(), ticker: z.string(), decimals: z.string(), contractAddress: z.string().optional(), }); export const GetTokenDetailsResponseSchema = z.object({ token: TokenInfoSchema, }); export type GetTokenDetailsResponse = z.infer<typeof GetTokenDetailsResponseSchema>;