Skip to main content
Glama

QUOTE

Get real-time price quotes for token swaps on decentralized exchanges. Input token addresses and amounts to calculate exchange rates across multiple blockchain networks.

Instructions

Quote the price of a specific trading pair

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chainNoThe blockchain network to execute the transaction on. uses fraxtal as defaultfraxtal
inTokenAddressYesThe token to swap from (address).
outTokenAddressYesThe token to swap to (address).
amountYesToken amount with decimals. For example, if 1 USDT is input, use 1000000 (1 USDT * 10^6).
slippageNoDefine the acceptable slippage level by inputting a percentage value within the range of 0.05 to 50. 1% slippage set as 1.1

Implementation Reference

  • The main execution handler for the QUOTE tool. Processes arguments, retrieves chain and gas price data, calls SwapService.quote, and returns the formatted quote response.
    export const quote = async (args: z.infer<typeof getQuoteParamsSchema>) => { try { const inputChain = args.chain.toLowerCase(); const chainObject = getChainFromName(inputChain); console.error(`[QUOTE] Using chain: ${chainObject.name}`, args); const chainService = new ChainService(); const gasRes: any = await chainService.gasPrice(chainObject.id); const gasPrice = gasRes.data.fast; const swapService = new SwapService(); const quote = await swapService.quote( args.inTokenAddress, args.outTokenAddress, chainObject.id, args.amount, args.slippage ? Number(args.slippage) * 100 : 100, gasPrice, ); if (quote instanceof Error) { return `Error fetching quote: ${quote.message}`; } // return JSON.stringify(quote); return JSON.stringify(quote, null, 2); } catch (error: unknown) { const message = error instanceof Error ? error.message : "An unknown error occurred while fetching quote."; console.error(`[QUOTE] Error: ${message}`); throw new Error(`Failed to fetch quote: ${message}`); } };
  • Registers the QUOTE tool in the tools object, defining its name, description, input parameters schema, and the execute handler.
    quote: { name: "QUOTE", description: "Quote the price of a specific trading pair", parameters: getQuoteParamsSchema, execute: swapExecute.quote },
  • Zod schema defining the input parameters for the QUOTE tool, including chain, token addresses, amount, and optional slippage.
    export const getQuoteParamsSchema = z.object({ chain: z .string() .optional() .describe( "The blockchain network to execute the transaction on. uses fraxtal as default", ) .default("fraxtal"), inTokenAddress: z .string() .refine(isAddress, { message: "Invalid inToken address" }) .describe("The token to swap from (address)."), outTokenAddress: z .string() .refine(isAddress, { message: "Invalid outToken address" }) .describe("The token to swap to (address)."), amount: z .string() .regex(/^\d+$/, { message: "Amount must be a string in wei (no decimals)" }) .describe("Token amount with decimals. For example, if 1 USDT is input, use 1000000 (1 USDT * 10^6). "), slippage: z .string() .optional() .describe("Define the acceptable slippage level by inputting a percentage value within the range of 0.05 to 50. 1% slippage set as 1.") .default('1'), });
  • TypeScript interface for the expected output/response structure of the QUOTE tool.
    export interface QuoteResponse { inToken: token; outToken: token; inAmount: number; outAmount: number; estimatedGas: number; }

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/openocean-finance/openocean-mcp'

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