Repository: alchemyplatform/alchemy-sdk-js
Pull request #91 (2022-08-10 20:53:06)

Add pageSize param to `getNftsForOwner()`


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index eb28e964..fdaa891d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,9 @@
 
 ## Unreleased
 
+### Minor Changes
+- Added support for the `pageSize` parameter in `GetNftsForOwnerOptions` to specify the number of NFTs fetched when using `alchemy.nft.getNftsForOwner()`.
+
 ## 2.0.2
 
 ### Major Changes
@@ -12,7 +15,7 @@
 
 - Removed the deprecated `TOKEN` enum from `AssetTransfersCategory`.
 - Added support for Optimism Goerli network via the `Network.OPT_GOERLI` enum.
-- Added the `pageSize` parameter in `GetNftsForContractOption` to specify the number of NFTs fetched when using `alchemy.nft.getNftsForContract`.
+- Added the `pageSize` parameter in `GetNftsForContractOptions` to specify the number of NFTs fetched when using `alchemy.nft.getNftsForContract`.
 - Added correct `withMetadata` typing to `AssetTransfersResponse`.
 
 ## 2.0.1
diff --git a/src/internal/nft-api.ts b/src/internal/nft-api.ts
index e30dfead..9e0334e9 100644
--- a/src/internal/nft-api.ts
+++ b/src/internal/nft-api.ts
@@ -126,6 +126,7 @@ export async function getNftsForOwner(
     pageKey: options?.pageKey,
     filters: options?.excludeFilters,
     owner,
+    pageSize: options?.pageSize,
     withMetadata
   });
   return {
@@ -451,6 +452,7 @@ interface GetNftsAlchemyParams {
   pageKey?: string;
   contractAddresses?: string[];
   filters?: string[];
+  pageSize?: number;
   withMetadata: boolean;
 }
 
diff --git a/src/types/types.ts b/src/types/types.ts
index d3286316..242d7734 100644
--- a/src/types/types.ts
+++ b/src/types/types.ts
@@ -254,6 +254,12 @@ export interface GetNftsForOwnerOptions {
    */
   excludeFilters?: NftExcludeFilters[];
 
+  /**
+   * Sets the total number of NFTs to return in the response. Defaults to 100.
+   * Maximum page size is 100.
+   */
+  pageSize?: number;
+
   /** Optional boolean flag to omit NFT metadata. Defaults to `false`. */
   omitMetadata?: boolean;
 }
@@ -283,6 +289,12 @@ export interface GetBaseNftsForOwnerOptions {
    */
   excludeFilters?: NftExcludeFilters[];
 
+  /**
+   * Sets the total number of NFTs to return in the response. Defaults to 100.
+   * Maximum page size is 100.
+   */
+  pageSize?: number;
+
   /** Optional boolean flag to include NFT metadata. Defaults to `false`. */
   omitMetadata: true;
 }
@@ -512,7 +524,10 @@ export interface GetNftsForContractOptions {
   /** Optional boolean flag to omit NFT metadata. Defaults to `false`. */
   omitMetadata?: boolean;
 
-  /** Sets the total number of NFTs to return in the response. Defaults to 100. */
+  /**
+   * Sets the total number of NFTs to return in the response. Defaults to 100.
+   * Maximum page size is 100.
+   */
   pageSize?: number;
 }
 
@@ -535,7 +550,10 @@ export interface GetBaseNftsForContractOptions {
   /** Optional boolean flag to omit NFT metadata. Defaults to `false`. */
   omitMetadata: false;
 
-  /** Sets the total number of NFTs to return in the response. Defaults to 100. */
+  /**
+   * Sets the total number of NFTs to return in the response. Defaults to 100.
+   * Maximum page size is 100.
+   */
   pageSize?: number;
 }
 


Test patch:
diff --git a/test/integration/integration.test.ts b/test/integration/integration.test.ts
index 81678b75..59dde861 100644
--- a/test/integration/integration.test.ts
+++ b/test/integration/integration.test.ts
@@ -97,6 +97,13 @@ describe('E2E integration tests', () => {
     expect(response.owners.length).toBeGreaterThan(0);
   });
 
+  it('getNftForOwners with pageSize', async () => {
+    const response = await alchemy.nft.getNftsForOwner('0xshah.eth', {
+      pageSize: 51
+    });
+    expect(response.ownedNfts.length).toEqual(10);
+  });
+
   it('getOwnersForNft from NFT', async () => {
     const nfts = await alchemy.nft.getNftsForOwner(ownerAddress, {
       excludeFilters: [NftExcludeFilters.SPAM],
diff --git a/test/unit/nft-api.test.ts b/test/unit/nft-api.test.ts
index 964884e2..2cd0f30c 100644
--- a/test/unit/nft-api.test.ts
+++ b/test/unit/nft-api.test.ts
@@ -212,7 +212,8 @@ describe('NFT module', () => {
     const getNftsParams: GetNftsForOwnerOptions = {
       pageKey,
       contractAddresses,
-      excludeFilters
+      excludeFilters,
+      pageSize: 3
     };
     const baseNftResponse: RawGetBaseNftsResponse = {
       ownedNfts: [
@@ -259,6 +260,7 @@ describe('NFT module', () => {
           expectedFilters
         );
         expect(mock.history.get[0].params).toHaveProperty('pageKey', pageKey);
+        expect(mock.history.get[0].params).toHaveProperty('pageSize', 3);
         expect(mock.history.get[0].params).toHaveProperty(
           'withMetadata',
           expectedWithMetadata