import {z} from 'zod' export type GetApiGetTransactionInfoArgs = {chain_id: string, transaction_hash: string, include_raw_input?: boolean | undefined}; export type GetApiGetTransactionInfoOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const pagination = z.object({next_call: z.object({tool_name: z.string(), params: z.object({cursor: z.string()}).and(z.record(z.string(), z.unknown()))})}); export const toolResponse = z.object({data: z.union([z.object({}), z.array(z.unknown()), z.string(), z.number(), z.boolean()]).nullable(), data_description: z.array(z.string()).nullable().optional(), notes: z.array(z.string()).nullable().optional(), instructions: z.array(z.string()).nullable().optional(), pagination: pagination.nullable().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Get transaction info * * GET /get_transaction_info */ export const getApiGetTransactionInfo = async (args: GetApiGetTransactionInfoArgs, options?: GetApiGetTransactionInfoOptions) => { const {baseUrl = "https://mcp.blockscout.com/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.chain_id != null) query.append("chain_id", String(args.chain_id)) if (args.transaction_hash != null) query.append("transaction_hash", String(args.transaction_hash)) if (args.include_raw_input != null) query.append("include_raw_input", String(args.include_raw_input)) const url = `${baseUrl.replace(/\/+$/, '')}/get_transaction_info${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(toolResponse, await res.json()) };