thirdweb 5.95.0-nightly-e7b01108037ebef07fba95f888be1905c8fab5df-20250417000348 → 5.95.0-nightly-4cf15a2475fce1c5b55d19f7cf51ab080e80e33f-20250418000341

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/cjs/extensions/erc1155/read/getNFT.js +38 -0
  2. package/dist/cjs/extensions/erc1155/read/getNFT.js.map +1 -1
  3. package/dist/cjs/extensions/erc1155/read/getNFTs.js +26 -0
  4. package/dist/cjs/extensions/erc1155/read/getNFTs.js.map +1 -1
  5. package/dist/cjs/extensions/erc1155/read/getOwnedNFTs.js +46 -0
  6. package/dist/cjs/extensions/erc1155/read/getOwnedNFTs.js.map +1 -1
  7. package/dist/cjs/insight/get-nfts.js +67 -12
  8. package/dist/cjs/insight/get-nfts.js.map +1 -1
  9. package/dist/cjs/rpc/fetch-rpc.js +2 -22
  10. package/dist/cjs/rpc/fetch-rpc.js.map +1 -1
  11. package/dist/cjs/rpc/rpc.js +1 -1
  12. package/dist/cjs/rpc/rpc.js.map +1 -1
  13. package/dist/cjs/version.js +1 -1
  14. package/dist/cjs/wallets/in-app/core/users/getUser.js +2 -1
  15. package/dist/cjs/wallets/in-app/core/users/getUser.js.map +1 -1
  16. package/dist/esm/extensions/erc1155/read/getNFT.js +38 -0
  17. package/dist/esm/extensions/erc1155/read/getNFT.js.map +1 -1
  18. package/dist/esm/extensions/erc1155/read/getNFTs.js +26 -0
  19. package/dist/esm/extensions/erc1155/read/getNFTs.js.map +1 -1
  20. package/dist/esm/extensions/erc1155/read/getOwnedNFTs.js +46 -0
  21. package/dist/esm/extensions/erc1155/read/getOwnedNFTs.js.map +1 -1
  22. package/dist/esm/insight/get-nfts.js +67 -12
  23. package/dist/esm/insight/get-nfts.js.map +1 -1
  24. package/dist/esm/rpc/fetch-rpc.js +2 -22
  25. package/dist/esm/rpc/fetch-rpc.js.map +1 -1
  26. package/dist/esm/rpc/rpc.js +1 -1
  27. package/dist/esm/rpc/rpc.js.map +1 -1
  28. package/dist/esm/version.js +1 -1
  29. package/dist/esm/wallets/in-app/core/users/getUser.js +2 -1
  30. package/dist/esm/wallets/in-app/core/users/getUser.js.map +1 -1
  31. package/dist/types/extensions/erc1155/read/getNFT.d.ts +5 -0
  32. package/dist/types/extensions/erc1155/read/getNFT.d.ts.map +1 -1
  33. package/dist/types/extensions/erc1155/read/getNFTs.d.ts +5 -0
  34. package/dist/types/extensions/erc1155/read/getNFTs.d.ts.map +1 -1
  35. package/dist/types/extensions/erc1155/read/getOwnedNFTs.d.ts +7 -1
  36. package/dist/types/extensions/erc1155/read/getOwnedNFTs.d.ts.map +1 -1
  37. package/dist/types/insight/get-nfts.d.ts.map +1 -1
  38. package/dist/types/rpc/fetch-rpc.d.ts.map +1 -1
  39. package/dist/types/rpc/rpc.d.ts.map +1 -1
  40. package/dist/types/version.d.ts +1 -1
  41. package/dist/types/wallets/in-app/core/users/getUser.d.ts.map +1 -1
  42. package/package.json +2 -2
  43. package/src/extensions/erc1155/read/getNFT.test.ts +11 -0
  44. package/src/extensions/erc1155/read/getNFT.ts +51 -1
  45. package/src/extensions/erc1155/read/getNFTs.ts +38 -0
  46. package/src/extensions/erc1155/read/getOwnedNFTs.ts +65 -2
  47. package/src/extensions/erc721/read/getNFT.test.ts +81 -83
  48. package/src/extensions/erc721/read/getNFTs.test.ts +189 -189
  49. package/src/insight/get-nfts.ts +112 -48
  50. package/src/rpc/fetch-rpc.ts +2 -20
  51. package/src/rpc/rpc.ts +5 -1
  52. package/src/version.ts +1 -1
  53. package/src/wallets/in-app/core/users/getUser.test.ts +4 -1
  54. package/src/wallets/in-app/core/users/getUser.ts +4 -1
@@ -1,3 +1,4 @@
1
+ import { getOwnedNFTs as getInsightNFTs } from "../../../insight/get-nfts.js";
1
2
  import type { BaseTransactionOptions } from "../../../transaction/types.js";
2
3
  import type { NFT } from "../../../utils/nft/parseNft.js";
3
4
  import { getNFT } from "./getNFT.js";
@@ -5,12 +6,17 @@ import {
5
6
  type GetOwnedTokenIdsParams,
6
7
  getOwnedTokenIds,
7
8
  } from "./getOwnedTokenIds.js";
8
-
9
9
  /**
10
10
  * Parameters for retrieving NFTs.
11
11
  * @extension ERC1155
12
12
  */
13
- export type GetOwnedNFTsParams = GetOwnedTokenIdsParams;
13
+ export type GetOwnedNFTsParams = GetOwnedTokenIdsParams & {
14
+ /**
15
+ * Whether to use the insight API to fetch the NFTs.
16
+ * @default true
17
+ */
18
+ useIndexer?: boolean;
19
+ };
14
20
 
15
21
  /**
16
22
  * Retrieves the owned ERC1155 NFTs for a given wallet address.
@@ -30,6 +36,63 @@ export type GetOwnedNFTsParams = GetOwnedTokenIdsParams;
30
36
  */
31
37
  export async function getOwnedNFTs(
32
38
  options: BaseTransactionOptions<GetOwnedNFTsParams>,
39
+ ): Promise<(NFT & { quantityOwned: bigint })[]> {
40
+ const { useIndexer = true } = options;
41
+ if (useIndexer) {
42
+ try {
43
+ return await getOwnedNFTsFromInsight(options);
44
+ } catch {
45
+ return await getOwnedNFTsFromRPC(options);
46
+ }
47
+ }
48
+ return await getOwnedNFTsFromRPC(options);
49
+ }
50
+
51
+ async function getOwnedNFTsFromInsight(
52
+ options: BaseTransactionOptions<GetOwnedNFTsParams>,
53
+ ): Promise<(NFT & { quantityOwned: bigint })[]> {
54
+ const limit = 50;
55
+ const nfts: (NFT & { quantityOwned: bigint })[] = [];
56
+ let page = 0;
57
+ let hasMore = true;
58
+
59
+ // TODO (insight): add support for contract address filters
60
+ while (hasMore) {
61
+ const pageResults = await getInsightNFTs({
62
+ client: options.contract.client,
63
+ chains: [options.contract.chain],
64
+ ownerAddress: options.address,
65
+ queryOptions: {
66
+ limit,
67
+ page,
68
+ },
69
+ });
70
+
71
+ nfts.push(...pageResults);
72
+
73
+ // If we got fewer results than the limit, we've reached the end
74
+ if (pageResults.length < limit) {
75
+ hasMore = false;
76
+ } else {
77
+ page++;
78
+ }
79
+ }
80
+
81
+ const results = nfts;
82
+
83
+ return results
84
+ .filter(
85
+ (n) =>
86
+ n.tokenAddress.toLowerCase() === options.contract.address.toLowerCase(),
87
+ )
88
+ .map((result) => ({
89
+ ...result,
90
+ owner: options.address,
91
+ }));
92
+ }
93
+
94
+ async function getOwnedNFTsFromRPC(
95
+ options: BaseTransactionOptions<GetOwnedNFTsParams>,
33
96
  ): Promise<(NFT & { quantityOwned: bigint })[]> {
34
97
  const ownedBalances = await getOwnedTokenIds(options);
35
98
 
@@ -10,46 +10,45 @@ describe.runIf(process.env.TW_SECRET_KEY)("erc721.getNFT", () => {
10
10
  includeOwner: false,
11
11
  });
12
12
  expect(nft.metadata.name).toBe("Doodle #1");
13
- // TODO (insight): re-enable once insight fixes the client id caching issue
14
- // expect(nft).toMatchInlineSnapshot(`
15
- // {
16
- // "chainId": 1,
17
- // "id": 1n,
18
- // "metadata": {
19
- // "attributes": [
20
- // {
21
- // "trait_type": "face",
22
- // "value": "holographic beard",
23
- // },
24
- // {
25
- // "trait_type": "hair",
26
- // "value": "white bucket cap",
27
- // },
28
- // {
29
- // "trait_type": "body",
30
- // "value": "purple sweater with satchel",
31
- // },
32
- // {
33
- // "trait_type": "background",
34
- // "value": "grey",
35
- // },
36
- // {
37
- // "trait_type": "head",
38
- // "value": "gradient 2",
39
- // },
40
- // ],
41
- // "description": "A community-driven collectibles project featuring art by Burnt Toast. Doodles come in a joyful range of colors, traits and sizes with a collection size of 10,000. Each Doodle allows its owner to vote for experiences and activations paid for by the Doodles Community Treasury. Burnt Toast is the working alias for Scott Martin, a Canadian–based illustrator, designer, animator and muralist.",
42
- // "image": "https://${clientId}.ipfscdn.io/ipfs/QmTDxnzcvj2p3xBrKcGv1wxoyhAn2yzCQnZZ9LmFjReuH9",
43
- // "image_url": "https://${clientId}.ipfscdn.io/ipfs/QmTDxnzcvj2p3xBrKcGv1wxoyhAn2yzCQnZZ9LmFjReuH9",
44
- // "name": "Doodle #1",
45
- // "uri": "https://${clientId}.ipfscdn.io/ipfs/QmPMc4tcBsMqLRuCQtPmPe84bpSjrC3Ky7t3JWuHXYB4aS/1",
46
- // },
47
- // "owner": null,
48
- // "tokenAddress": "0x8a90cab2b38dba80c64b7734e58ee1db38b8992e",
49
- // "tokenURI": "https://${clientId}.ipfscdn.io/ipfs/QmPMc4tcBsMqLRuCQtPmPe84bpSjrC3Ky7t3JWuHXYB4aS/1",
50
- // "type": "ERC721",
51
- // }
52
- // `);
13
+ expect(nft).toMatchInlineSnapshot(`
14
+ {
15
+ "chainId": 1,
16
+ "id": 1n,
17
+ "metadata": {
18
+ "attributes": [
19
+ {
20
+ "trait_type": "face",
21
+ "value": "holographic beard",
22
+ },
23
+ {
24
+ "trait_type": "hair",
25
+ "value": "white bucket cap",
26
+ },
27
+ {
28
+ "trait_type": "body",
29
+ "value": "purple sweater with satchel",
30
+ },
31
+ {
32
+ "trait_type": "background",
33
+ "value": "grey",
34
+ },
35
+ {
36
+ "trait_type": "head",
37
+ "value": "gradient 2",
38
+ },
39
+ ],
40
+ "description": "A community-driven collectibles project featuring art by Burnt Toast. Doodles come in a joyful range of colors, traits and sizes with a collection size of 10,000. Each Doodle allows its owner to vote for experiences and activations paid for by the Doodles Community Treasury. Burnt Toast is the working alias for Scott Martin, a Canadian–based illustrator, designer, animator and muralist.",
41
+ "image": "ipfs://QmTDxnzcvj2p3xBrKcGv1wxoyhAn2yzCQnZZ9LmFjReuH9",
42
+ "image_url": "ipfs://QmTDxnzcvj2p3xBrKcGv1wxoyhAn2yzCQnZZ9LmFjReuH9",
43
+ "name": "Doodle #1",
44
+ "uri": "ipfs://QmPMc4tcBsMqLRuCQtPmPe84bpSjrC3Ky7t3JWuHXYB4aS/1",
45
+ },
46
+ "owner": null,
47
+ "tokenAddress": "0x8a90cab2b38dba80c64b7734e58ee1db38b8992e",
48
+ "tokenURI": "ipfs://QmPMc4tcBsMqLRuCQtPmPe84bpSjrC3Ky7t3JWuHXYB4aS/1",
49
+ "type": "ERC721",
50
+ }
51
+ `);
53
52
  });
54
53
 
55
54
  it("with owner using indexer", async () => {
@@ -60,49 +59,48 @@ describe.runIf(process.env.TW_SECRET_KEY)("erc721.getNFT", () => {
60
59
  });
61
60
  expect(nft.metadata.name).toBe("Doodle #1");
62
61
  expect(nft.owner).toBe("0xbe9936fcfc50666f5425fde4a9decc59cef73b24");
63
- // TODO (insight): re-enable once insight fixes the client id caching issue
64
- // expect(nft).toMatchInlineSnapshot(`
65
- // {
66
- // "chainId": 1,
67
- // "id": 1n,
68
- // "metadata": {
69
- // "attributes": [
70
- // {
71
- // "trait_type": "face",
72
- // "value": "holographic beard",
73
- // },
74
- // {
75
- // "trait_type": "hair",
76
- // "value": "white bucket cap",
77
- // },
78
- // {
79
- // "trait_type": "body",
80
- // "value": "purple sweater with satchel",
81
- // },
82
- // {
83
- // "trait_type": "background",
84
- // "value": "grey",
85
- // },
86
- // {
87
- // "trait_type": "head",
88
- // "value": "gradient 2",
89
- // },
90
- // ],
91
- // "description": "A community-driven collectibles project featuring art by Burnt Toast. Doodles come in a joyful range of colors, traits and sizes with a collection size of 10,000. Each Doodle allows its owner to vote for experiences and activations paid for by the Doodles Community Treasury. Burnt Toast is the working alias for Scott Martin, a Canadian–based illustrator, designer, animator and muralist.",
92
- // "image": "https://${clientId}.ipfscdn.io/ipfs/QmTDxnzcvj2p3xBrKcGv1wxoyhAn2yzCQnZZ9LmFjReuH9",
93
- // "image_url": "https://${clientId}.ipfscdn.io/ipfs/QmTDxnzcvj2p3xBrKcGv1wxoyhAn2yzCQnZZ9LmFjReuH9",
94
- // "name": "Doodle #1",
95
- // "owner_addresses": [
96
- // "0xbe9936fcfc50666f5425fde4a9decc59cef73b24",
97
- // ],
98
- // "uri": "https://${clientId}.ipfscdn.io/ipfs/QmPMc4tcBsMqLRuCQtPmPe84bpSjrC3Ky7t3JWuHXYB4aS/1",
99
- // },
100
- // "owner": "0xbe9936fcfc50666f5425fde4a9decc59cef73b24",
101
- // "tokenAddress": "0x8a90cab2b38dba80c64b7734e58ee1db38b8992e",
102
- // "tokenURI": "https://${clientId}.ipfscdn.io/ipfs/QmPMc4tcBsMqLRuCQtPmPe84bpSjrC3Ky7t3JWuHXYB4aS/1",
103
- // "type": "ERC721",
104
- // }
105
- // `);
62
+ expect(nft).toMatchInlineSnapshot(`
63
+ {
64
+ "chainId": 1,
65
+ "id": 1n,
66
+ "metadata": {
67
+ "attributes": [
68
+ {
69
+ "trait_type": "face",
70
+ "value": "holographic beard",
71
+ },
72
+ {
73
+ "trait_type": "hair",
74
+ "value": "white bucket cap",
75
+ },
76
+ {
77
+ "trait_type": "body",
78
+ "value": "purple sweater with satchel",
79
+ },
80
+ {
81
+ "trait_type": "background",
82
+ "value": "grey",
83
+ },
84
+ {
85
+ "trait_type": "head",
86
+ "value": "gradient 2",
87
+ },
88
+ ],
89
+ "description": "A community-driven collectibles project featuring art by Burnt Toast. Doodles come in a joyful range of colors, traits and sizes with a collection size of 10,000. Each Doodle allows its owner to vote for experiences and activations paid for by the Doodles Community Treasury. Burnt Toast is the working alias for Scott Martin, a Canadian–based illustrator, designer, animator and muralist.",
90
+ "image": "ipfs://QmTDxnzcvj2p3xBrKcGv1wxoyhAn2yzCQnZZ9LmFjReuH9",
91
+ "image_url": "ipfs://QmTDxnzcvj2p3xBrKcGv1wxoyhAn2yzCQnZZ9LmFjReuH9",
92
+ "name": "Doodle #1",
93
+ "owner_addresses": [
94
+ "0xbe9936fcfc50666f5425fde4a9decc59cef73b24",
95
+ ],
96
+ "uri": "ipfs://QmPMc4tcBsMqLRuCQtPmPe84bpSjrC3Ky7t3JWuHXYB4aS/1",
97
+ },
98
+ "owner": "0xbe9936fcfc50666f5425fde4a9decc59cef73b24",
99
+ "tokenAddress": "0x8a90cab2b38dba80c64b7734e58ee1db38b8992e",
100
+ "tokenURI": "ipfs://QmPMc4tcBsMqLRuCQtPmPe84bpSjrC3Ky7t3JWuHXYB4aS/1",
101
+ "type": "ERC721",
102
+ }
103
+ `);
106
104
  });
107
105
 
108
106
  it("without owner", async () => {