import {z} from 'zod' export type CreateApiAnkrGetTransactionsByHashArgs = {body: {id: number, jsonrpc: '2.0', method: 'ankr_getTransactionsByHash', params: {transactionHash: string, blockchain?: (Array<'arbitrum' | 'avalanche' | 'base' | 'bsc' | 'eth' | 'fantom' | 'flare' | 'gnosis' | 'linea' | 'optimism' | 'polygon' | 'scroll' | 'somnia_mainnet' | 'taiko' | 'telos' | 'xlayer' | 'avalanche_fuji' | 'base_sepolia' | 'eth_sepolia' | 'optimism_sepolia' | 'polygon_amoy'>) | undefined, decodeLogs?: boolean | undefined, decodeTxData?: boolean | undefined, includeLogs?: boolean | undefined}}}; export type CreateApiAnkrGetTransactionsByHashOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiAnkrGetTransactionsByHashResponse = z.object({id: z.number().int(), jsonrpc: z.literal("2.0"), result: z.object({transactions: z.array(z.object({blockchain: z.string(), blockHash: z.string(), blockNumber: z.string(), contractAddress: z.string().nullable().optional(), cumulativeGasUsed: z.string().optional(), from: z.string(), gas: z.string().optional(), gasPrice: z.string().optional(), gasUsed: z.string().optional(), hash: z.string().optional(), input: z.string().optional(), nonce: z.string().optional(), r: z.string().optional(), s: z.string().optional(), status: z.string(), timestamp: z.string(), to: z.string().nullable(), transactionIndex: z.string(), type: z.string().optional(), v: z.string().optional(), value: z.string(), logs: z.array(z.object({})).nullable().optional()})).nullable()})}); 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 }; /** * Look up a transaction by hash, optionally with decoded data and logs * * POST /?ankr_getTransactionsByHash */ export const createApiAnkrGetTransactionsByHash = async (args: CreateApiAnkrGetTransactionsByHashArgs, options?: CreateApiAnkrGetTransactionsByHashOptions) => { const {baseUrl = "https://rpc.ankr.com/multichain/569ca1f392f7d3d0bb1073a1173ecb649af1d9249231fe59fa95db19d5ae41fe", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/?ankr_getTransactionsByHash${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiAnkrGetTransactionsByHashResponse, await res.json()) };