fetchTransfers
Query blockchain transfer data by specifying sender, receiver, contract addresses, and block ranges to analyze transaction flows.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| fromBlock | No | The block number to start the search from. e.g. "1234567890". Inclusive from block (hex string, int, latest, or indexed). | 0x0 |
| toBlock | No | The block number to end the search at. e.g. "1234567890". Inclusive to block (hex string, int, latest, or indexed). | latest |
| fromAddress | No | The wallet address to query the transfer was sent from. | |
| toAddress | No | The wallet address to query the transfer was sent to. | |
| contractAddresses | No | The contract addresses to query. e.g. ["0x1234567890123456789012345678901234567890"] | |
| category | No | The category of transfers to query. e.g. "external" or "internal" | |
| order | No | The order of the results. e.g. "asc" or "desc". | asc |
| withMetadata | No | Whether to include metadata in the results. | |
| excludeZeroValue | No | Whether to exclude zero value transfers. | |
| maxCount | No | The maximum number of results to return. e.g. "0x3E8". | 0xA |
| pageKey | No | The cursor to start the search from. Use this to paginate through the results. | |
| network | No | The blockchain network to query. e.g. "eth-mainnet" or "base-mainnet"). | eth-mainnet |
Implementation Reference
- index.ts:229-248 (handler)The handler function registered for the 'fetchTransfers' MCP tool. It calls alchemyApi.getAssetTransfers with the input params and returns the result as formatted JSON text, handling errors appropriately.}, async (params) => { try { const result = await alchemyApi.getAssetTransfers(params); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], }; } catch (error) { if (error instanceof Error) { console.error('Error in fetchTransfers:', error); return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true }; } return { content: [{ type: "text", text: 'Unknown error occurred' }], isError: true }; } });
- index.ts:216-227 (schema)Zod schema defining the input parameters for the 'fetchTransfers' tool, matching Alchemy's getAssetTransfers API.fromBlock: z.string().default('0x0').describe('The block number to start the search from. e.g. "1234567890". Inclusive from block (hex string, int, latest, or indexed).'), toBlock: z.string().default('latest').describe('The block number to end the search at. e.g. "1234567890". Inclusive to block (hex string, int, latest, or indexed).'), fromAddress: z.string().optional().describe('The wallet address to query the transfer was sent from.'), toAddress: z.string().optional().describe('The wallet address to query the transfer was sent to.'), contractAddresses: z.array(z.string()).default([]).describe('The contract addresses to query. e.g. ["0x1234567890123456789012345678901234567890"]'), category: z.array(z.string()).default(['external', 'erc20']).describe('The category of transfers to query. e.g. "external" or "internal"'), order: z.string().default('asc').describe('The order of the results. e.g. "asc" or "desc".'), withMetadata: z.boolean().default(false).describe('Whether to include metadata in the results.'), excludeZeroValue: z.boolean().default(true).describe('Whether to exclude zero value transfers.'), maxCount: z.string().default('0xA').describe('The maximum number of results to return. e.g. "0x3E8".'), pageKey: z.string().optional().describe('The cursor to start the search from. Use this to paginate through the results.'), network: z.string().default('eth-mainnet').describe('The blockchain network to query. e.g. "eth-mainnet" or "base-mainnet").'),
- index.ts:215-215 (registration)Registration of the 'fetchTransfers' tool on the MCP server.server.tool('fetchTransfers', {
- api/alchemyApi.ts:104-121 (helper)Helper function implementing the core logic to fetch asset transfers by calling the Alchemy JSON-RPC method 'alchemy_getAssetTransfers'.async getAssetTransfers(params: AssetTransfersParams) { const { network, ...otherParams } = params; try { const client = createAlchemyJsonRpcClient(network); const response = await client.post('', { method: "alchemy_getAssetTransfers", params: [{ ...otherParams }] }); return response.data; } catch (error) { console.error('Error fetching asset transfers:', error); throw error; } },
- types/types.d.ts:35-48 (schema)TypeScript interface defining the parameters for asset transfers, used in the alchemyApi.getAssetTransfers function.export interface AssetTransfersParams { fromBlock: string; toBlock: string; fromAddress?: string; toAddress?: string; contractAddresses: string[]; category: string[]; order: string; withMetadata: boolean; excludeZeroValue: boolean; maxCount: string; pageKey?: string; network: string; }