fetchAddressTransactionHistory
Retrieve transaction history for specified wallet addresses across multiple blockchain networks using the Alchemy MCP Server, enabling pagination and custom result limits.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| addresses | Yes | A list of wallet address and network pairs | |
| after | No | The cursor that points to the next set of results. Use this to paginate through the results. | |
| before | No | The cursor that points to the previous set of results. Use this to paginate through the results. | |
| limit | No | The number of results to return. Default is 25. Max is 100 |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"addresses": {
"description": "A list of wallet address and network pairs",
"items": {
"additionalProperties": false,
"properties": {
"address": {
"description": "The wallet address to query. e.g. \"0x1234567890123456789012345678901234567890\"",
"type": "string"
},
"networks": {
"description": "The blockchain networks to query. e.g. [\"eth-mainnet\", \"base-mainnet\"]",
"items": {
"type": "string"
},
"type": "array"
}
},
"required": [
"address",
"networks"
],
"type": "object"
},
"type": "array"
},
"after": {
"description": "The cursor that points to the next set of results. Use this to paginate through the results.",
"type": "string"
},
"before": {
"description": "The cursor that points to the previous set of results. Use this to paginate through the results.",
"type": "string"
},
"limit": {
"default": 25,
"description": "The number of results to return. Default is 25. Max is 100",
"type": "number"
}
},
"required": [
"addresses"
],
"type": "object"
}
Implementation Reference
- index.ts:183-210 (handler)Inline asynchronous handler function that executes the core logic for the 'fetchAddressTransactionHistory' tool: fetches transaction history via alchemyApi, formats timestamps and ETH values using utility functions, and returns formatted JSON response or error.}, async (params) => { try { let result = await alchemyApi.getTransactionHistoryByMultichainAddress(params); // List the transaction hash when returning the result to the user const formattedTxns = result.transactions.map((transaction: any) => ({ ...transaction, date: convertTimestampToDate(transaction.blockTimestamp), ethValue: convertWeiToEth(transaction.value) })); result.transactions = formattedTxns; return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], }; } catch (error) { if (error instanceof Error) { console.error('Error in getTransactionHistoryByMultichainAddress:', error); return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true }; } return { content: [{ type: "text", text: 'Unknown error occurred' }], isError: true }; } });
- index.ts:175-210 (registration)Registration of the 'fetchAddressTransactionHistory' MCP tool using server.tool(), including Zod input schema validation and inline handler.server.tool('fetchAddressTransactionHistory', { addresses: z.array(z.object({ address: z.string().describe('The wallet address to query. e.g. "0x1234567890123456789012345678901234567890"'), networks: z.array(z.string()).describe('The blockchain networks to query. e.g. ["eth-mainnet", "base-mainnet"]') })).describe('A list of wallet address and network pairs'), before: z.string().optional().describe('The cursor that points to the previous set of results. Use this to paginate through the results.'), after: z.string().optional().describe('The cursor that points to the next set of results. Use this to paginate through the results.'), limit: z.number().default(25).optional().describe('The number of results to return. Default is 25. Max is 100') }, async (params) => { try { let result = await alchemyApi.getTransactionHistoryByMultichainAddress(params); // List the transaction hash when returning the result to the user const formattedTxns = result.transactions.map((transaction: any) => ({ ...transaction, date: convertTimestampToDate(transaction.blockTimestamp), ethValue: convertWeiToEth(transaction.value) })); result.transactions = formattedTxns; return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], }; } catch (error) { if (error instanceof Error) { console.error('Error in getTransactionHistoryByMultichainAddress:', error); return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true }; } return { content: [{ type: "text", text: 'Unknown error occurred' }], isError: true }; } });
- types/types.d.ts:28-32 (schema)TypeScript interface defining the input structure for the fetchAddressTransactionHistory tool parameters, matching the Zod schema.export interface MultiChainTransactionHistoryByAddress extends MultiChainTokenByAddress { before?: string; after?: string; limit?: number; }
- api/alchemyApi.ts:84-102 (helper)Helper function in alchemyApi that handles the HTTP POST request to Alchemy's multi-chain transaction history API endpoint using the dedicated client.async getTransactionHistoryByMultichainAddress(params: MultiChainTransactionHistoryByAddress) { try { const { addresses, ...otherParams } = params; const client = createMultiChainTransactionHistoryClient(); const response = await client.post('/by-address', { addresses: params.addresses.map((pair: AddressPair) => ({ address: pair.address, networks: pair.networks })), ...otherParams }); return response.data; } catch (error) { console.error('Error fetching transaction history:', error); throw error; } },
- utils/convertTimestampToDate.ts:1-6 (helper)Utility helper function used in the tool handler to convert Unix timestamps from transaction data to human-readable dates.export function convertTimestampToDate(unixTimestamp: number) { const date = new Date(unixTimestamp); const humanReadableDate = date.toLocaleString(); return humanReadableDate; }