@@ -104,16 +104,29 @@ async function getNFTsFromInsight(
104104) : Promise < NFT [ ] > {
105105 const { contract, start, count = Number ( DEFAULT_QUERY_ALL_COUNT ) } = options ;
106106
107- const result = await getContractNFTs ( {
108- client : contract . client ,
109- chains : [ contract . chain ] ,
110- contractAddress : contract . address ,
111- includeOwners : options . includeOwners ?? false ,
112- queryOptions : {
113- limit : count ,
114- page : start ? Math . floor ( start / count ) : undefined ,
115- } ,
116- } ) ;
107+ const [ result , supply ] = await Promise . all ( [
108+ getContractNFTs ( {
109+ client : contract . client ,
110+ chains : [ contract . chain ] ,
111+ contractAddress : contract . address ,
112+ includeOwners : options . includeOwners ?? false ,
113+ queryOptions : {
114+ limit : count ,
115+ page : start ? Math . floor ( start / count ) : undefined ,
116+ } ,
117+ } ) ,
118+ totalSupply ( options ) ,
119+ ] ) ;
120+
121+ const currentOffset = start ?? 0 ;
122+ const expectedResultLength = Math . min (
123+ count ,
124+ Math . max ( 0 , Number ( supply ) - currentOffset ) ,
125+ ) ;
126+ if ( result . length < expectedResultLength ) {
127+ // fresh contracts might be delayed in indexing, so we fallback to RPC
128+ return getNFTsFromRPC ( options ) ;
129+ }
117130
118131 return result ;
119132}
@@ -158,6 +171,7 @@ async function getNFTsFromRPC(
158171 ...options ,
159172 tokenId : i ,
160173 includeOwner : options . includeOwners ?? false ,
174+ useIndexer : false ,
161175 } ) ,
162176 ) ;
163177 }
0 commit comments