Skip to main content
Glama
getERCTransfers.ts6.29 kB
import { z } from "zod"; import axios, { AxiosResponse } from "axios"; import { baseUri, chainName } from "../../constants"; interface ERC20Transfer { block_number: number; block_timestamp: string; contract: { address: string; decimals: number; erc_type: string; logoUri: null; name: string; symbol: string; }; from_address: string; log_index: number; to_address: string; transaction_hash: string; value: string; } interface ERCTransfersResponse { cursor: string; resultCount: number; transfers: ( | ERC20Transfer | ERC721TransfersResponse | ERC1155TransfersResponse )[]; } //for erc721 transfers interface ERC721TransfersResponse { amount: number; block_number: number; block_timestamp: string; from_address: string; log_index: number; to_address: string; token: { address: string; erc_type: string; metadata: { attributes: string; description: string; imageUri: string; mintedBlockNumber: number; mintedTimestamp: string; name: string; symbol: string; }; name: string; symbol: string; token_id: string; }; transaction_hash: string; } //for erc1155 transfers interface ERC1155TransfersResponse { amount: number; block_number: number; block_timestamp: string; from_address: string; log_index: number; to_address: string; token: { address: string; erc_type: string; metadata: { attributes: string; description: string; imageUri: string; mintedBlockNumber: number; mintedTimestamp: string; name: string; symbol: string; }; name: string; symbol: string; token_id: string; }; transaction_hash: string; } export default function (server: any) { server.tool( "getERC20Transfers", "Get ERC20 transfers for a specific wallet address", { chainName: z.literal(chainName), walletAddress: z .string() .describe("Wallet address to fetch ERC transfers for"), authToken: z .string() .describe("Authorization token for accessing the Somnia API"), }, { title: "Get ERC20 Transfers", readOnlyHint: true, description: "Fetch the ERC20 transfers for a specific wallet address.", destructiveHint: false, idempotentHint: true, }, async (args: any) => { const { chainName, walletAddress, authToken } = args; try { const response: AxiosResponse<ERCTransfersResponse> = await axios.get( `${baseUri}/${chainName}/v1/address/${walletAddress}/transfers/erc20`, { headers: { Authorization: `Bearer ${authToken}`, "Content-Type": "application/json", Accept: "application/json", }, } ); return { content: [ { type: "text", text: `ERC Transfers Data: ${JSON.stringify(response.data)}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error fetching ERC transfers: ${error}`, }, ], }; } } ); server.tool( "getERC721Transfers", "Get ERC721 transfers for a specific wallet address", { chainName: z.literal(chainName), walletAddress: z .string() .describe("Wallet address to fetch ERC721 transfers for"), authToken: z .string() .describe("Authorization token for accessing the Somnia API"), }, { title: "Get ERC721 Transfers", readOnlyHint: true, description: "Fetch the ERC721 transfers for a specific wallet address.", destructiveHint: false, idempotentHint: true, }, async (args: any) => { const { chainName, walletAddress, authToken } = args; try { const response: AxiosResponse<ERC721TransfersResponse> = await axios.get( `${baseUri}/${chainName}/v1/address/${walletAddress}/transfers/erc721`, { headers: { Authorization: `Bearer ${authToken}`, "Content-Type": "application/json", Accept: "application/json", }, } ); return { content: [ { type: "text", text: `ERC721 Transfers Data: ${JSON.stringify(response.data)}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error fetching ERC721 transfers: ${error}`, }, ], }; } } ); server.tool( "getERC1155Transfers", "Get ERC1155 transfers for a specific wallet address", { chainName: z.literal(chainName), walletAddress: z .string() .describe("Wallet address to fetch ERC1155 transfers for"), authToken: z .string() .describe("Authorization token for accessing the Somnia API"), }, { title: "Get ERC1155 Transfers", readOnlyHint: true, description: "Fetch the ERC1155 transfers for a specific wallet address.", destructiveHint: false, idempotentHint: true, }, async (args: any) => { const { chainName, walletAddress, authToken } = args; try { const response: AxiosResponse<ERC1155TransfersResponse> = await axios.get( `${baseUri}/${chainName}/v1/address/${walletAddress}/transfers/erc1155`, { headers: { Authorization: `Bearer ${authToken}`, "Content-Type": "application/json", Accept: "application/json", }, } ); return { content: [ { type: "text", text: `ERC1155 Transfers Data: ${JSON.stringify(response.data)}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error fetching ERC1155 transfers: ${error}`, }, ], }; } } ); }

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/vastavikadi/somnia-mcp'

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