Repository: alchemyplatform/alchemy-sdk-js
Pull request #110 (2022-09-07 17:03:49)

Fix totalSupply typing bug
This fixes the payload type to match what is actually returned by the backend. I want to double check here, but I don't think this requires a major version bump since we're fixing a bug.

dphilipson: Pragmatically, I think it's not worth counting typing changes as breaking changes. This is because literally any change that improves typing is "breaking" in the sense that now things that previously passed type checking no longer do: this is the whole point of improving typing.

You'll notice that TypeScript itself follows this convention: many versions of typescript contains "breaking" changes in the sense that things that previously passed typechecks no longer do, but they only rarely update the major version (which is currently only v4).

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1afab30d..53a91e29 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,11 @@
 # Changelog for Alchemy SDK for JavaScript
 
 ## Unreleased
+
+## Major Changes
+- POTENTIALLY BREAKING: Fixed a typing bug where the `totalSupply` field in an `NftContract` should have type `string` instead of `number`.
+
+### Minor Changes
 - Added a `size` field to the `Media` object in the NFT metadata responses to indicate the size of the media in bytes.
 
 ## 2.0.3
diff --git a/src/api/nft.ts b/src/api/nft.ts
index 4e9585d8..0fc5eeec 100644
--- a/src/api/nft.ts
+++ b/src/api/nft.ts
@@ -21,8 +21,8 @@ export interface NftContract extends BaseNftContract {
   name?: string;
   /** The symbol of the contract. */
   symbol?: string;
-  /** The number of NFTs in the contract. */
-  totalSupply?: number;
+  /** The number of NFTs in the contract as an integer string. */
+  totalSupply?: string;
 }
 
 /**
diff --git a/src/internal/raw-interfaces.ts b/src/internal/raw-interfaces.ts
index 4163235d..e4c91633 100644
--- a/src/internal/raw-interfaces.ts
+++ b/src/internal/raw-interfaces.ts
@@ -55,7 +55,7 @@ export interface RawNftContract {
 interface RawNftContractMetadata {
   name?: string;
   symbol?: string;
-  totalSupply?: number;
+  totalSupply?: string;
   tokenType: NftTokenType;
 }
 


Test patch:
diff --git a/test/test-util.ts b/test/test-util.ts
index 2c65938a..b8261029 100644
--- a/test/test-util.ts
+++ b/test/test-util.ts
@@ -30,7 +30,7 @@ export function createRawNftContract(
   tokenType: NftTokenType,
   name?: string,
   symbol?: string,
-  totalSupply?: number
+  totalSupply?: string
 ): RawNftContract {
   return {
     address,
diff --git a/test/unit/nft-api.test.ts b/test/unit/nft-api.test.ts
index 294266b4..96726f73 100644
--- a/test/unit/nft-api.test.ts
+++ b/test/unit/nft-api.test.ts
@@ -58,7 +58,7 @@ describe('NFT module', () => {
     const address = '0xABC';
     const name = 'NFT Contract Name';
     const symbol = 'NCN';
-    const totalSupply = 9999;
+    const totalSupply = '9999';
     const tokenType = NftTokenType.ERC721;
 
     const rawNftContractResponse = createRawNftContract(
@@ -80,7 +80,7 @@ describe('NFT module', () => {
       address: string,
       name: string,
       symbol: string,
-      totalSupply: number,
+      totalSupply: string,
       tokenType?: NftTokenType
     ) {
       expect(actualNftContract).toEqual(expectedNftContract);