@@ -7,7 +7,6 @@ import type {
77 Chain ,
88 ChainMetadata ,
99 ChainOptions ,
10- ChainService ,
1110 LegacyChain ,
1211} from "./types.js" ;
1312
@@ -323,62 +322,22 @@ export function getChainMetadata(chain: Chain): Promise<ChainMetadata> {
323322 ) ;
324323}
325324
326- type FetchChainServiceResponse =
327- | {
328- data : {
329- services : ChainService [ ] ;
330- } ;
331- error ?: never ;
332- }
333- | {
334- data ?: never ;
335- error : unknown ;
336- } ;
337-
338- /**
339- * Retrieves a list of services available on a given chain
340- * @param chain - The chain object containing the chain ID.
341- * @returns A Promise that resolves to chain services.
342- * @throws If there is an error fetching the chain services.
343- * @example
344- * ```ts
345- * const chain = defineChain({ id: 1 });
346- * const chainServices = await getChainServices(chain);
347- * console.log(chainServices);
348- * ```
349- * @chain
350- */
351- export function getChainServices ( chain : Chain ) : Promise < ChainService [ ] > {
352- const chainId = chain . id ;
325+ export async function getInsightEnabledChainIds ( ) : Promise < number [ ] > {
353326 return withCache (
354327 async ( ) => {
355- try {
356- const res = await fetch (
357- `https://api.thirdweb.com/v1/chains/${ chainId } /services` ,
328+ const res = await fetch (
329+ `https://api.thirdweb.com/v1/chains/services?service=insight` ,
330+ ) ;
331+ if ( ! res . ok ) {
332+ throw new Error (
333+ `Failed to fetch services. ${ res . status } ${ res . statusText } ` ,
358334 ) ;
359- if ( ! res . ok ) {
360- throw new Error (
361- `Failed to fetch services for chainId ${ chainId } . ${ res . status } ${ res . statusText } ` ,
362- ) ;
363- }
364-
365- const response = ( await res . json ( ) ) as FetchChainServiceResponse ;
366- if ( response . error ) {
367- throw new Error ( `Failed to fetch services for chainId ${ chainId } ` ) ;
368- }
369- if ( ! response . data ) {
370- throw new Error ( `Failed to fetch services for chainId ${ chainId } ` ) ;
371- }
372-
373- const services = response . data . services ;
374-
375- return services ;
376- } catch {
377- throw new Error ( `Failed to fetch services for chainId ${ chainId } ` ) ;
378335 }
336+ const response = ( await res . json ( ) ) as { data : Record < number , boolean > } ;
337+ return Object . keys ( response . data ) . map ( ( chainId ) => Number ( chainId ) ) ;
379338 } ,
380339 {
381- cacheKey : `chain:${ chainId } :services ` ,
340+ cacheKey : `chain:insight-enabled ` ,
382341 cacheTime : 24 * 60 * 60 * 1000 , // 1 day
383342 } ,
384343 ) ;
0 commit comments