tm_get_price
Retrieve current token prices in USDC using zero-cost quotes. Automatically resolves token symbols to addresses without requiring API keys.
Instructions
Get the current price of a token in USDC by running a zero-cost quote.
Resolves token symbols (SOL, ETH) to addresses automatically. Does NOT require an API key — only auth token.
Args:
token (string): Token symbol (e.g. "SOL") or contract address
chain (string): "solana" or "base" (default: "solana")
Returns: { token, chain, price_usdc, qty_in, qty_out }
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| token | Yes | Token symbol (SOL, ETH) or contract address | |
| chain | No | Blockchain network | solana |
Implementation Reference
- src/tools/read.ts:34-77 (handler)The handler function for the `tm_get_price` tool which resolves token symbols and fetches a quote from the API to calculate the price.
async ({ token, chain }) => { // Resolve symbol to address if needed let baseAsset = token; let resolvedChain = chain; if (isSymbol(token)) { const assets = await api.getAssets(); const match = assets.find( (a) => a.symbol?.toLowerCase() === token.toLowerCase() ); if (!match?.address) { return { isError: true, content: [{ type: "text", text: `Could not resolve symbol "${token}". Use tm_list_assets to see available tokens.` }], }; } baseAsset = match.address; if (match.chain) resolvedChain = match.chain.toLowerCase() as "solana" | "base"; } const quote = await api.createQuote({ order_side: "buy", chain: resolvedChain, base_asset: baseAsset, quote_asset: getQuoteAsset(resolvedChain), qty: "1", }); const price = parseFloat(quote.qty) / parseFloat(quote.qty_out); const output = { token: token.toUpperCase(), chain: resolvedChain, price_usdc: price.toFixed(6), qty_in: quote.qty, qty_out: quote.qty_out, fee: quote.fee, }; return { content: [{ type: "text", text: JSON.stringify(output, null, 2) }], structuredContent: output, }; } - src/tools/read.ts:11-33 (registration)The schema definition and registration parameters for `tm_get_price`.
{ title: "Get token price", description: `Get the current price of a token in USDC by running a zero-cost quote. Resolves token symbols (SOL, ETH) to addresses automatically. Does NOT require an API key — only auth token. Args: - token (string): Token symbol (e.g. "SOL") or contract address - chain (string): "solana" or "base" (default: "solana") Returns: { token, chain, price_usdc, qty_in, qty_out }`, inputSchema: { token: z.string().describe("Token symbol (SOL, ETH) or contract address"), chain: z.enum(["solana", "base"]).default("solana").describe("Blockchain network"), }, annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true, }, },