@@ -63,7 +63,7 @@ export async function getNftMetadata(
63
63
tokenType ?: NftTokenType
64
64
) : Promise < Nft > {
65
65
let response ;
66
- let contractAddress = '' ;
66
+ let contractAddress : string ;
67
67
if ( typeof contractAddressOrBaseNft === 'string' ) {
68
68
validateContractAddress ( contractAddressOrBaseNft ) ;
69
69
contractAddress = contractAddressOrBaseNft ;
@@ -95,7 +95,7 @@ export async function getNftMetadata(
95
95
}
96
96
97
97
/**
98
- * - Fetches all NFTs for a given owner and yields them in an async iterable.
98
+ * Fetches all NFTs for a given owner and yields them in an async iterable.
99
99
*
100
100
* This method returns the base NFTs that omit the associated metadata and pages
101
101
* through all page keys until all NFTs have been fetched.
@@ -126,10 +126,16 @@ export async function* getNftsPaginated(
126
126
params : GetNftsParams | GetBaseNftsParams
127
127
) : AsyncIterable < OwnedBaseNft | OwnedNft > {
128
128
const withMetadata = params . withMetadata ?? true ;
129
- for await ( const response of paginateEndpoint ( alchemy , 'getNFTs' , 'pageKey' , {
130
- ...params ,
131
- withMetadata
132
- } ) ) {
129
+ for await ( const response of paginateEndpoint (
130
+ alchemy ,
131
+ 'getNFTs' ,
132
+ 'pageKey' ,
133
+ 'pageKey' ,
134
+ {
135
+ ...params ,
136
+ withMetadata
137
+ }
138
+ ) ) {
133
139
for ( const ownedNft of response . ownedNfts as
134
140
| RawOwnedNft [ ]
135
141
| RawOwnedBaseNft [ ] ) {
@@ -199,7 +205,6 @@ export async function getNfts(
199
205
* @param params The parameters to use for the request.
200
206
* @beta
201
207
*/
202
- // TODO: Add pagination for this endpoint.
203
208
export async function getNftsForCollection (
204
209
alchemy : Alchemy ,
205
210
params : GetBaseNftsForCollectionParams
@@ -216,7 +221,6 @@ export async function getNftsForCollection(
216
221
* {@link CollectionNftsResponse} response.
217
222
* @beta
218
223
*/
219
- // TODO: add pagination for this endpoint.
220
224
export async function getNftsForCollection (
221
225
alchemy : Alchemy ,
222
226
params : GetNftsForCollectionParams
@@ -287,6 +291,63 @@ export function getOwnersForToken(
287
291
}
288
292
}
289
293
294
+ /**
295
+ * Fetches all base NFTs for a given contract address and yields them in an
296
+ * async iterable.
297
+ *
298
+ * This method returns the base NFTs that omit the associated metadata and pages
299
+ * through all page keys until all NFTs have been fetched. To get all NFTs with
300
+ * their associated metadata, use {@link GetNftsForCollectionParams}.
301
+ *
302
+ * @param alchemy The Alchemy SDK instance.
303
+ * @param params The parameters to use for the request.
304
+ * @beta
305
+ */
306
+ export function getNftsForCollectionPaginated (
307
+ alchemy : Alchemy ,
308
+ params : GetBaseNftsForCollectionParams
309
+ ) : AsyncIterable < BaseNft > ;
310
+
311
+ /**
312
+ * Fetches all NFTs for a given contract address and yields them in an async iterable.
313
+ *
314
+ * This method returns the full NFTs in the contract and pages through all page
315
+ * keys until all NFTs have been fetched. To get all NFTs without their
316
+ * associated metadata, use {@link GetBaseNftsForCollectionParams}.
317
+ *
318
+ * @param alchemy The Alchemy SDK instance.
319
+ * @param params The parameters to use for the request.
320
+ * @beta
321
+ */
322
+ export function getNftsForCollectionPaginated (
323
+ alchemy : Alchemy ,
324
+ params : GetNftsForCollectionParams
325
+ ) : AsyncIterable < Nft > ;
326
+ export async function * getNftsForCollectionPaginated (
327
+ alchemy : Alchemy ,
328
+ params : GetBaseNftsForCollectionParams | GetNftsForCollectionParams
329
+ ) : AsyncIterable < BaseNft | Nft > {
330
+ const withMetadata =
331
+ params . withMetadata !== undefined ? params . withMetadata : true ;
332
+ for await ( const response of paginateEndpoint (
333
+ alchemy ,
334
+ 'getNFTsForCollection' ,
335
+ 'startToken' ,
336
+ 'nextToken' ,
337
+ {
338
+ contractAddress : params . contractAddress ,
339
+ startToken : params . pageKey ,
340
+ withMetadata
341
+ }
342
+ ) ) {
343
+ for ( const nft of response . nfts as
344
+ | RawCollectionBaseNft [ ]
345
+ | RawCollectionNft [ ] ) {
346
+ yield nftFromGetNftCollectionResponse ( nft , params . contractAddress ) ;
347
+ }
348
+ }
349
+ }
350
+
290
351
/**
291
352
* Helper method to convert a NFT response received from Alchemy backend to an
292
353
* SDK NFT type.
0 commit comments