import {z} from 'zod' export type GetApiV1AllchainsTransactionsArgs = {chains?: string | undefined, addresses?: string | undefined, limit?: number | undefined, before?: string | undefined, after?: string | undefined, 'with-logs'?: boolean | undefined, 'with-decoded-logs'?: boolean | undefined, 'quote-currency'?: string | undefined, 'with-input-data'?: boolean | undefined}; export type GetApiV1AllchainsTransactionsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV1AllchainsTransactionsResponse = z.object({updated_at: z.string().optional(), cursor_before: z.string().optional(), cursor_after: z.string().optional(), quote_currency: z.string().optional(), items: z.array(z.object({block_height: z.number().int().optional(), block_signed_at: z.string().optional(), block_hash: z.string().optional(), tx_hash: z.string().optional(), tx_offset: z.number().int().optional(), miner_address: z.string().optional(), from_address: z.string().optional(), to_address: z.string().optional(), value: z.string().optional(), value_quote: z.number().optional(), pretty_value_quote: z.string().optional(), gas_offered: z.number().int().optional(), gas_spent: z.number().int().optional(), gas_price: z.number().int().optional(), gas_quote: z.number().optional(), pretty_gas_quote: z.string().optional(), gas_quote_rate: z.number().optional(), fees_paid: z.string().optional(), gas_metadata: z.object({contract_decimals: z.number().int().optional(), contract_name: z.string().optional(), contract_ticker_symbol: z.string().optional(), contract_address: z.string().optional(), supports_erc: z.array(z.string()).optional(), logo_url: z.string().optional()}).optional(), successful: z.boolean().optional(), chain_id: z.string().optional(), chain_name: z.string().optional(), explorers: z.array(z.object({label: z.string().optional(), url: z.string().optional()})).optional(), log_events: z.array(z.object({block_signed_at: z.string().optional(), block_height: z.number().int().optional(), tx_offset: z.number().int().optional(), log_offset: z.number().int().optional(), tx_hash: z.string().optional(), raw_log_topics: z.array(z.string()).optional(), sender_contract_decimals: z.number().int().optional(), sender_name: z.string().optional(), sender_contract_ticker_symbol: z.string().optional(), sender_address: z.string().optional(), sender_logo_url: z.string().optional(), supports_erc: z.array(z.string()).optional(), sender_factory_address: z.string().optional(), raw_log_data: z.string().optional(), decoded: z.object({name: z.string().optional(), signature: z.string().optional(), params: z.array(z.object({name: z.string().optional(), type: z.string().optional(), indexed: z.boolean().optional(), decoded: z.boolean().optional(), value: z.string().optional()})).optional()}).optional()})).optional(), input_data: z.object({method_id: z.string().optional()}).optional()})).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 }; /** * Fetch paginated transactions for up to 10 EVM addresses and 10 EVM chains with one API call. Useful for building Activity Feeds. * * GET /v1/allchains/transactions/ */ export const getApiV1AllchainsTransactions = async (args: GetApiV1AllchainsTransactionsArgs, options?: GetApiV1AllchainsTransactionsOptions) => { const {baseUrl = "https://api.covalenthq.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.chains != null) query.append("chains", String(args.chains)) if (args.addresses != null) query.append("addresses", String(args.addresses)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.before != null) query.append("before", String(args.before)) if (args.after != null) query.append("after", String(args.after)) if (args['with-logs'] != null) query.append("with-logs", String(args['with-logs'])) if (args['with-decoded-logs'] != null) query.append("with-decoded-logs", String(args['with-decoded-logs'])) if (args['quote-currency'] != null) query.append("quote-currency", String(args['quote-currency'])) if (args['with-input-data'] != null) query.append("with-input-data", String(args['with-input-data'])) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/allchains/transactions/${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(getApiV1AllchainsTransactionsResponse, await res.json()) };