Skip to main content
Glama

fetchTokenPriceByAddress

Retrieve token prices by providing contract addresses and blockchain networks, enabling quick and accurate token value queries across multiple chains via Alchemy MCP Server.

Input Schema

NameRequiredDescriptionDefault
addressesYesA list of token contract address and network pairs

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "addresses": { "description": "A list of token contract address and network pairs", "items": { "additionalProperties": false, "properties": { "address": { "description": "The token contract address to query. e.g. \"0x1234567890123456789012345678901234567890\"", "type": "string" }, "network": { "description": "The blockchain network to query. e.g. \"eth-mainnet\" or \"base-mainnet\"", "type": "string" } }, "required": [ "address", "network" ], "type": "object" }, "type": "array" } }, "required": [ "addresses" ], "type": "object" }

Implementation Reference

  • Core handler function that executes the logic for fetching token price by address using Alchemy Prices API via POST to /by-address endpoint.
    async getTokenPriceByAddress(params: TokenPriceByAddress) { try { const client = createPricesClient(); const response = await client.post('/by-address', { addresses: params.addresses.map((pair: TokenPriceByAddressPair) => ({ address: pair.address, network: pair.network })) }); console.log('Successfully fetched token price:', response.data); return response.data; } catch (error) { console.error('Error fetching token price:', error); throw error; } },
  • TypeScript interfaces defining the input parameters for the fetchTokenPriceByAddress tool.
    export interface TokenPriceByAddress { addresses: TokenPriceByAddressPair[]; } export interface TokenPriceByAddressPair { address: string; network: string; }
  • index.ts:41-65 (registration)
    Registers the fetchTokenPriceByAddress tool with Zod input schema and wrapper handler that calls the core alchemyApi function and formats response.
    server.tool('fetchTokenPriceByAddress', { addresses: z.array(z.object({ address: z.string().describe('The token contract address to query. e.g. "0x1234567890123456789012345678901234567890"'), network: z.string().describe('The blockchain network to query. e.g. "eth-mainnet" or "base-mainnet"') })).describe('A list of token contract address and network pairs'), }, async (params) => { try { const result = await alchemyApi.getTokenPriceByAddress(params); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], }; } catch (error) { if (error instanceof Error) { console.error('Error in getTokenPriceByAddress:', error); return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true }; } return { content: [{ type: "text", text: 'Unknown error occurred' }], isError: true }; } });
  • Helper function to create Axios client configured for Alchemy Prices API, used in the token price handler.
    export const createPricesClient = () => axios.create({ baseURL: `https://api.g.alchemy.com/prices/v1/${API_KEY}/tokens`, headers: { 'accept': 'application/json', 'content-type': 'application/json', 'x-alchemy-client-breadcrumb': BREADCRUMB_HEADER }, });

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/alchemyplatform/alchemy-mcp-server'

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