export type TokenContractInput = {address: string, chain: string}; export type BatchTokensRequest = {contracts: Array}; export type CreateApiApiV2TokensBatchArgs = {body: BatchTokensRequest}; export type CreateApiApiV2TokensBatchOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Get tokens by contract identifiers * * POST /api/v2/tokens/batch */ export const createApiApiV2TokensBatch = async (args: CreateApiApiV2TokensBatchArgs, options?: CreateApiApiV2TokensBatchOptions) => { const {baseUrl = "https://api.opensea.io", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "*/*") if (ApiKeyAuth !== undefined) headers.set("x-api-key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/tokens/batch${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 res.blob() };