thirdweb 5.95.0-nightly-64bd603301b3067b6a69a29f66a28dee7ffa38f5-20250416000349 → 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 (230) hide show
  1. package/dist/cjs/chains/utils.js +2 -4
  2. package/dist/cjs/chains/utils.js.map +1 -1
  3. package/dist/cjs/event/actions/get-events.js +4 -10
  4. package/dist/cjs/event/actions/get-events.js.map +1 -1
  5. package/dist/cjs/extensions/erc1155/read/getNFT.js +40 -0
  6. package/dist/cjs/extensions/erc1155/read/getNFT.js.map +1 -1
  7. package/dist/cjs/extensions/erc1155/read/getNFTs.js +26 -0
  8. package/dist/cjs/extensions/erc1155/read/getNFTs.js.map +1 -1
  9. package/dist/cjs/extensions/erc1155/read/getOwnedNFTs.js +46 -0
  10. package/dist/cjs/extensions/erc1155/read/getOwnedNFTs.js.map +1 -1
  11. package/dist/cjs/extensions/erc20/read/getBalance.js +2 -0
  12. package/dist/cjs/extensions/erc20/read/getBalance.js.map +1 -1
  13. package/dist/cjs/extensions/erc721/read/getNFT.js +42 -0
  14. package/dist/cjs/extensions/erc721/read/getNFT.js.map +1 -1
  15. package/dist/cjs/extensions/erc721/read/getNFTs.js +44 -17
  16. package/dist/cjs/extensions/erc721/read/getNFTs.js.map +1 -1
  17. package/dist/cjs/extensions/erc721/read/getOwnedNFTs.js +46 -0
  18. package/dist/cjs/extensions/erc721/read/getOwnedNFTs.js.map +1 -1
  19. package/dist/cjs/extensions/marketplace/direct-listings/utils.js +7 -4
  20. package/dist/cjs/extensions/marketplace/direct-listings/utils.js.map +1 -1
  21. package/dist/cjs/extensions/marketplace/english-auctions/utils.js +9 -4
  22. package/dist/cjs/extensions/marketplace/english-auctions/utils.js.map +1 -1
  23. package/dist/cjs/extensions/marketplace/offers/utils.js +7 -4
  24. package/dist/cjs/extensions/marketplace/offers/utils.js.map +1 -1
  25. package/dist/cjs/insight/common.js +18 -0
  26. package/dist/cjs/insight/common.js.map +1 -0
  27. package/dist/cjs/insight/get-events.js +12 -9
  28. package/dist/cjs/insight/get-events.js.map +1 -1
  29. package/dist/cjs/insight/get-nfts.js +213 -16
  30. package/dist/cjs/insight/get-nfts.js.map +1 -1
  31. package/dist/cjs/insight/get-tokens.js +34 -14
  32. package/dist/cjs/insight/get-tokens.js.map +1 -1
  33. package/dist/cjs/insight/get-transactions.js +17 -12
  34. package/dist/cjs/insight/get-transactions.js.map +1 -1
  35. package/dist/cjs/insight/index.js +3 -1
  36. package/dist/cjs/insight/index.js.map +1 -1
  37. package/dist/cjs/react/web/ui/ConnectWallet/screens/ViewNFTs.js +6 -43
  38. package/dist/cjs/react/web/ui/ConnectWallet/screens/ViewNFTs.js.map +1 -1
  39. package/dist/cjs/react/web/ui/ConnectWallet/screens/ViewTokens.js +3 -9
  40. package/dist/cjs/react/web/ui/ConnectWallet/screens/ViewTokens.js.map +1 -1
  41. package/dist/cjs/react/web/ui/components/TokenIcon.js +3 -1
  42. package/dist/cjs/react/web/ui/components/TokenIcon.js.map +1 -1
  43. package/dist/cjs/react/web/ui/prebuilt/NFT/utils.js +7 -2
  44. package/dist/cjs/react/web/ui/prebuilt/NFT/utils.js.map +1 -1
  45. package/dist/cjs/rpc/fetch-rpc.js +2 -22
  46. package/dist/cjs/rpc/fetch-rpc.js.map +1 -1
  47. package/dist/cjs/rpc/rpc.js +1 -1
  48. package/dist/cjs/rpc/rpc.js.map +1 -1
  49. package/dist/cjs/social/profiles.js +3 -8
  50. package/dist/cjs/social/profiles.js.map +1 -1
  51. package/dist/cjs/storage/download.js +2 -2
  52. package/dist/cjs/storage/download.js.map +1 -1
  53. package/dist/cjs/storage/unpin.js +2 -2
  54. package/dist/cjs/storage/unpin.js.map +1 -1
  55. package/dist/cjs/storage/upload/web-node.js +0 -1
  56. package/dist/cjs/storage/upload/web-node.js.map +1 -1
  57. package/dist/cjs/utils/nft/parseNft.js +4 -0
  58. package/dist/cjs/utils/nft/parseNft.js.map +1 -1
  59. package/dist/cjs/utils/signatures/resolve-signature.js +0 -2
  60. package/dist/cjs/utils/signatures/resolve-signature.js.map +1 -1
  61. package/dist/cjs/version.js +1 -1
  62. package/dist/cjs/wallets/in-app/core/users/getUser.js +2 -1
  63. package/dist/cjs/wallets/in-app/core/users/getUser.js.map +1 -1
  64. package/dist/cjs/wallets/smart/lib/calls.js +2 -2
  65. package/dist/cjs/wallets/smart/lib/calls.js.map +1 -1
  66. package/dist/cjs/wallets/utils/getWalletBalance.js +3 -0
  67. package/dist/cjs/wallets/utils/getWalletBalance.js.map +1 -1
  68. package/dist/esm/chains/utils.js +2 -4
  69. package/dist/esm/chains/utils.js.map +1 -1
  70. package/dist/esm/event/actions/get-events.js +1 -7
  71. package/dist/esm/event/actions/get-events.js.map +1 -1
  72. package/dist/esm/extensions/erc1155/read/getNFT.js +40 -0
  73. package/dist/esm/extensions/erc1155/read/getNFT.js.map +1 -1
  74. package/dist/esm/extensions/erc1155/read/getNFTs.js +26 -0
  75. package/dist/esm/extensions/erc1155/read/getNFTs.js.map +1 -1
  76. package/dist/esm/extensions/erc1155/read/getOwnedNFTs.js +46 -0
  77. package/dist/esm/extensions/erc1155/read/getOwnedNFTs.js.map +1 -1
  78. package/dist/esm/extensions/erc20/read/getBalance.js +2 -0
  79. package/dist/esm/extensions/erc20/read/getBalance.js.map +1 -1
  80. package/dist/esm/extensions/erc721/read/getNFT.js +42 -0
  81. package/dist/esm/extensions/erc721/read/getNFT.js.map +1 -1
  82. package/dist/esm/extensions/erc721/read/getNFTs.js +44 -17
  83. package/dist/esm/extensions/erc721/read/getNFTs.js.map +1 -1
  84. package/dist/esm/extensions/erc721/read/getOwnedNFTs.js +46 -0
  85. package/dist/esm/extensions/erc721/read/getOwnedNFTs.js.map +1 -1
  86. package/dist/esm/extensions/marketplace/direct-listings/utils.js +7 -4
  87. package/dist/esm/extensions/marketplace/direct-listings/utils.js.map +1 -1
  88. package/dist/esm/extensions/marketplace/english-auctions/utils.js +9 -4
  89. package/dist/esm/extensions/marketplace/english-auctions/utils.js.map +1 -1
  90. package/dist/esm/extensions/marketplace/offers/utils.js +7 -4
  91. package/dist/esm/extensions/marketplace/offers/utils.js.map +1 -1
  92. package/dist/esm/insight/common.js +15 -0
  93. package/dist/esm/insight/common.js.map +1 -0
  94. package/dist/esm/insight/get-events.js +8 -5
  95. package/dist/esm/insight/get-events.js.map +1 -1
  96. package/dist/esm/insight/get-nfts.js +208 -13
  97. package/dist/esm/insight/get-nfts.js.map +1 -1
  98. package/dist/esm/insight/get-tokens.js +30 -10
  99. package/dist/esm/insight/get-tokens.js.map +1 -1
  100. package/dist/esm/insight/get-transactions.js +13 -8
  101. package/dist/esm/insight/get-transactions.js.map +1 -1
  102. package/dist/esm/insight/index.js +1 -1
  103. package/dist/esm/insight/index.js.map +1 -1
  104. package/dist/esm/react/web/ui/ConnectWallet/screens/ViewNFTs.js +6 -43
  105. package/dist/esm/react/web/ui/ConnectWallet/screens/ViewNFTs.js.map +1 -1
  106. package/dist/esm/react/web/ui/ConnectWallet/screens/ViewTokens.js +3 -9
  107. package/dist/esm/react/web/ui/ConnectWallet/screens/ViewTokens.js.map +1 -1
  108. package/dist/esm/react/web/ui/components/TokenIcon.js +3 -1
  109. package/dist/esm/react/web/ui/components/TokenIcon.js.map +1 -1
  110. package/dist/esm/react/web/ui/prebuilt/NFT/utils.js +7 -2
  111. package/dist/esm/react/web/ui/prebuilt/NFT/utils.js.map +1 -1
  112. package/dist/esm/rpc/fetch-rpc.js +2 -22
  113. package/dist/esm/rpc/fetch-rpc.js.map +1 -1
  114. package/dist/esm/rpc/rpc.js +1 -1
  115. package/dist/esm/rpc/rpc.js.map +1 -1
  116. package/dist/esm/social/profiles.js +3 -8
  117. package/dist/esm/social/profiles.js.map +1 -1
  118. package/dist/esm/storage/download.js +2 -2
  119. package/dist/esm/storage/download.js.map +1 -1
  120. package/dist/esm/storage/unpin.js +2 -2
  121. package/dist/esm/storage/unpin.js.map +1 -1
  122. package/dist/esm/storage/upload/web-node.js +0 -1
  123. package/dist/esm/storage/upload/web-node.js.map +1 -1
  124. package/dist/esm/utils/nft/parseNft.js +4 -0
  125. package/dist/esm/utils/nft/parseNft.js.map +1 -1
  126. package/dist/esm/utils/signatures/resolve-signature.js +0 -2
  127. package/dist/esm/utils/signatures/resolve-signature.js.map +1 -1
  128. package/dist/esm/version.js +1 -1
  129. package/dist/esm/wallets/in-app/core/users/getUser.js +2 -1
  130. package/dist/esm/wallets/in-app/core/users/getUser.js.map +1 -1
  131. package/dist/esm/wallets/smart/lib/calls.js +2 -2
  132. package/dist/esm/wallets/smart/lib/calls.js.map +1 -1
  133. package/dist/esm/wallets/utils/getWalletBalance.js +3 -0
  134. package/dist/esm/wallets/utils/getWalletBalance.js.map +1 -1
  135. package/dist/types/chains/utils.d.ts.map +1 -1
  136. package/dist/types/event/actions/get-events.d.ts.map +1 -1
  137. package/dist/types/extensions/erc1155/read/getNFT.d.ts +5 -0
  138. package/dist/types/extensions/erc1155/read/getNFT.d.ts.map +1 -1
  139. package/dist/types/extensions/erc1155/read/getNFTs.d.ts +5 -0
  140. package/dist/types/extensions/erc1155/read/getNFTs.d.ts.map +1 -1
  141. package/dist/types/extensions/erc1155/read/getOwnedNFTs.d.ts +7 -1
  142. package/dist/types/extensions/erc1155/read/getOwnedNFTs.d.ts.map +1 -1
  143. package/dist/types/extensions/erc20/read/getBalance.d.ts +2 -0
  144. package/dist/types/extensions/erc20/read/getBalance.d.ts.map +1 -1
  145. package/dist/types/extensions/erc721/read/getNFT.d.ts +5 -0
  146. package/dist/types/extensions/erc721/read/getNFT.d.ts.map +1 -1
  147. package/dist/types/extensions/erc721/read/getNFTs.d.ts +5 -0
  148. package/dist/types/extensions/erc721/read/getNFTs.d.ts.map +1 -1
  149. package/dist/types/extensions/erc721/read/getOwnedNFTs.d.ts +3 -1
  150. package/dist/types/extensions/erc721/read/getOwnedNFTs.d.ts.map +1 -1
  151. package/dist/types/extensions/marketplace/direct-listings/utils.d.ts.map +1 -1
  152. package/dist/types/extensions/marketplace/english-auctions/utils.d.ts.map +1 -1
  153. package/dist/types/extensions/marketplace/offers/utils.d.ts.map +1 -1
  154. package/dist/types/insight/common.d.ts +3 -0
  155. package/dist/types/insight/common.d.ts.map +1 -0
  156. package/dist/types/insight/get-events.d.ts +2 -2
  157. package/dist/types/insight/get-events.d.ts.map +1 -1
  158. package/dist/types/insight/get-nfts.d.ts +52 -4
  159. package/dist/types/insight/get-nfts.d.ts.map +1 -1
  160. package/dist/types/insight/get-tokens.d.ts +3 -3
  161. package/dist/types/insight/get-tokens.d.ts.map +1 -1
  162. package/dist/types/insight/get-transactions.d.ts +1 -1
  163. package/dist/types/insight/get-transactions.d.ts.map +1 -1
  164. package/dist/types/insight/index.d.ts +2 -2
  165. package/dist/types/insight/index.d.ts.map +1 -1
  166. package/dist/types/react/core/utils/wallet.d.ts +1 -1
  167. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.d.ts +1 -1
  168. package/dist/types/react/web/ui/ConnectWallet/screens/ViewNFTs.d.ts.map +1 -1
  169. package/dist/types/react/web/ui/ConnectWallet/screens/ViewTokens.d.ts.map +1 -1
  170. package/dist/types/react/web/ui/components/TokenIcon.d.ts.map +1 -1
  171. package/dist/types/react/web/ui/prebuilt/NFT/utils.d.ts.map +1 -1
  172. package/dist/types/rpc/fetch-rpc.d.ts.map +1 -1
  173. package/dist/types/rpc/rpc.d.ts.map +1 -1
  174. package/dist/types/social/profiles.d.ts.map +1 -1
  175. package/dist/types/storage/download.d.ts.map +1 -1
  176. package/dist/types/storage/unpin.d.ts.map +1 -1
  177. package/dist/types/storage/upload/web-node.d.ts.map +1 -1
  178. package/dist/types/utils/nft/parseNft.d.ts +8 -0
  179. package/dist/types/utils/nft/parseNft.d.ts.map +1 -1
  180. package/dist/types/utils/signatures/resolve-signature.d.ts.map +1 -1
  181. package/dist/types/version.d.ts +1 -1
  182. package/dist/types/wallets/in-app/core/users/getUser.d.ts.map +1 -1
  183. package/dist/types/wallets/utils/getWalletBalance.d.ts +2 -7
  184. package/dist/types/wallets/utils/getWalletBalance.d.ts.map +1 -1
  185. package/package.json +4 -4
  186. package/src/chains/utils.ts +6 -4
  187. package/src/event/actions/get-events.ts +1 -13
  188. package/src/extensions/erc1155/read/getNFT.test.ts +13 -0
  189. package/src/extensions/erc1155/read/getNFT.ts +53 -1
  190. package/src/extensions/erc1155/read/getNFTs.ts +38 -0
  191. package/src/extensions/erc1155/read/getOwnedNFTs.ts +65 -2
  192. package/src/extensions/erc20/drop20.test.ts +48 -132
  193. package/src/extensions/erc20/read/getBalance.test.ts +5 -9
  194. package/src/extensions/erc20/read/getBalance.ts +4 -0
  195. package/src/extensions/erc721/read/getNFT.test.ts +106 -0
  196. package/src/extensions/erc721/read/getNFT.ts +55 -1
  197. package/src/extensions/erc721/read/getNFTs.test.ts +212 -6
  198. package/src/extensions/erc721/read/getNFTs.ts +59 -20
  199. package/src/extensions/erc721/read/getOwnedNFTs.test.ts +27 -2
  200. package/src/extensions/erc721/read/getOwnedNFTs.ts +61 -1
  201. package/src/extensions/erc721/token721.test.ts +2 -0
  202. package/src/extensions/marketplace/direct-listings/direct-listings.test.ts +2 -18
  203. package/src/extensions/marketplace/direct-listings/utils.ts +7 -4
  204. package/src/extensions/marketplace/english-auctions/utils.ts +9 -4
  205. package/src/extensions/marketplace/offers/utils.ts +7 -4
  206. package/src/insight/common.ts +24 -0
  207. package/src/insight/get-events.ts +23 -9
  208. package/src/insight/get-nfts.ts +315 -20
  209. package/src/insight/get-tokens.ts +51 -23
  210. package/src/insight/get-transactions.ts +26 -16
  211. package/src/insight/index.ts +6 -2
  212. package/src/react/web/ui/ConnectWallet/screens/ViewNFTs.tsx +43 -68
  213. package/src/react/web/ui/ConnectWallet/screens/ViewTokens.tsx +4 -14
  214. package/src/react/web/ui/components/TokenIcon.tsx +12 -3
  215. package/src/react/web/ui/prebuilt/NFT/utils.test.ts +2 -64
  216. package/src/react/web/ui/prebuilt/NFT/utils.ts +7 -2
  217. package/src/rpc/fetch-rpc.ts +2 -20
  218. package/src/rpc/rpc.ts +5 -1
  219. package/src/social/profiles.ts +5 -9
  220. package/src/storage/download.ts +4 -2
  221. package/src/storage/unpin.ts +4 -2
  222. package/src/storage/upload/web-node.ts +0 -1
  223. package/src/utils/nft/parseNft.test.ts +8 -0
  224. package/src/utils/nft/parseNft.ts +12 -0
  225. package/src/utils/signatures/resolve-signature.ts +0 -2
  226. package/src/version.ts +1 -1
  227. package/src/wallets/in-app/core/users/getUser.test.ts +4 -1
  228. package/src/wallets/in-app/core/users/getUser.ts +4 -1
  229. package/src/wallets/smart/lib/calls.ts +2 -2
  230. package/src/wallets/utils/getWalletBalance.ts +5 -7
@@ -0,0 +1,24 @@
1
+ import type { Chain } from "../chains/types.js";
2
+ import { getChainServices } from "../chains/utils.js";
3
+
4
+ export async function assertInsightEnabled(chains: Chain[]) {
5
+ const chainData = await Promise.all(
6
+ chains.map((chain) =>
7
+ getChainServices(chain).then((services) => ({
8
+ chain,
9
+ enabled: services.some((c) => c.service === "insight" && c.enabled),
10
+ })),
11
+ ),
12
+ );
13
+
14
+ const insightEnabled = chainData.every((c) => c.enabled);
15
+
16
+ if (!insightEnabled) {
17
+ throw new Error(
18
+ `Insight is not available for chains ${chainData
19
+ .filter((c) => !c.enabled)
20
+ .map((c) => c.chain.id)
21
+ .join(", ")}`,
22
+ );
23
+ }
24
+ }
@@ -1,15 +1,11 @@
1
- import {
2
- type GetV1EventsByContractAddressData,
3
- type GetV1EventsByContractAddressResponse,
4
- getV1EventsByContractAddress,
1
+ import type {
2
+ GetV1EventsByContractAddressData,
3
+ GetV1EventsByContractAddressResponse,
5
4
  } from "@thirdweb-dev/insight";
6
5
  import type { AbiEvent } from "ox/AbiEvent";
7
- import { stringify } from "viem";
8
6
  import type { Chain } from "../chains/types.js";
9
7
  import type { ThirdwebClient } from "../client/client.js";
10
8
  import type { PreparedEvent } from "../event/prepare-event.js";
11
- import { getThirdwebDomains } from "../utils/domains.js";
12
- import { getClientFetch } from "../utils/fetch.js";
13
9
 
14
10
  export type ContractEvent = NonNullable<
15
11
  GetV1EventsByContractAddressResponse["data"]
@@ -37,11 +33,30 @@ export async function getContractEvents(options: {
37
33
  contractAddress: string;
38
34
  event?: PreparedEvent<AbiEvent>;
39
35
  decodeLogs?: boolean;
40
- queryOptions?: GetV1EventsByContractAddressData["query"];
36
+ queryOptions?: Omit<
37
+ GetV1EventsByContractAddressData["query"],
38
+ "chain" | "decode"
39
+ >;
41
40
  }): Promise<ContractEvent[]> {
41
+ const [
42
+ { getV1EventsByContractAddress },
43
+ { getThirdwebDomains },
44
+ { getClientFetch },
45
+ { assertInsightEnabled },
46
+ { stringify },
47
+ ] = await Promise.all([
48
+ import("@thirdweb-dev/insight"),
49
+ import("../utils/domains.js"),
50
+ import("../utils/fetch.js"),
51
+ import("./common.js"),
52
+ import("../utils/json.js"),
53
+ ]);
54
+
42
55
  const { client, chains, contractAddress, event, queryOptions, decodeLogs } =
43
56
  options;
44
57
 
58
+ await assertInsightEnabled(chains);
59
+
45
60
  const defaultQueryOptions: GetV1EventsByContractAddressData["query"] = {
46
61
  chain: chains.map((chain) => chain.id),
47
62
  limit: 100,
@@ -62,7 +77,6 @@ export async function getContractEvents(options: {
62
77
  contractAddress,
63
78
  },
64
79
  query: {
65
- chain: chains.map((chain) => chain.id),
66
80
  ...defaultQueryOptions,
67
81
  ...queryOptions,
68
82
  },
@@ -1,15 +1,18 @@
1
- import {
2
- type GetV1NftsBalanceByOwnerAddressData,
3
- type GetV1NftsBalanceByOwnerAddressResponse,
4
- getV1NftsBalanceByOwnerAddress,
1
+ import type {
2
+ GetV1NftsByContractAddressByTokenIdData,
3
+ GetV1NftsByContractAddressData,
4
+ GetV1NftsByContractAddressResponse,
5
+ GetV1NftsData,
6
+ GetV1NftsResponse,
5
7
  } from "@thirdweb-dev/insight";
6
- import { stringify } from "viem";
7
8
  import type { Chain } from "../chains/types.js";
8
9
  import type { ThirdwebClient } from "../client/client.js";
9
- import { getThirdwebDomains } from "../utils/domains.js";
10
- import { getClientFetch } from "../utils/fetch.js";
10
+ import type { NFT } from "../utils/nft/parseNft.js";
11
11
 
12
- export type OwnedNFT = GetV1NftsBalanceByOwnerAddressResponse["data"][number];
12
+ import { getCachedChain } from "../chains/utils.js";
13
+ import { getContract } from "../contract/contract.js";
14
+ type OwnedNFT = GetV1NftsResponse["data"][number];
15
+ type ContractNFT = GetV1NftsByContractAddressResponse["data"][number];
13
16
 
14
17
  /**
15
18
  * Get NFTs owned by an address
@@ -29,28 +32,200 @@ export async function getOwnedNFTs(args: {
29
32
  client: ThirdwebClient;
30
33
  chains: Chain[];
31
34
  ownerAddress: string;
32
- queryOptions?: GetV1NftsBalanceByOwnerAddressData["query"];
33
- }): Promise<OwnedNFT[]> {
35
+ includeMetadata?: boolean;
36
+ queryOptions?: Omit<GetV1NftsData["query"], "owner_address" | "chain">;
37
+ }): Promise<(NFT & { quantityOwned: bigint })[]> {
38
+ const [
39
+ { getV1Nfts },
40
+ { getThirdwebDomains },
41
+ { getClientFetch },
42
+ { assertInsightEnabled },
43
+ { stringify },
44
+ ] = await Promise.all([
45
+ import("@thirdweb-dev/insight"),
46
+ import("../utils/domains.js"),
47
+ import("../utils/fetch.js"),
48
+ import("./common.js"),
49
+ import("viem"),
50
+ ]);
51
+
52
+ // TODO (insight): add support for contract address filters
53
+ const { client, chains, ownerAddress, queryOptions } = args;
54
+
55
+ await assertInsightEnabled(chains);
56
+
57
+ const defaultQueryOptions: GetV1NftsData["query"] = {
58
+ chain: chains.map((chain) => chain.id),
59
+ // metadata: includeMetadata ? "true" : "false", TODO (insight): add support for this
60
+ limit: 50,
61
+ owner_address: ownerAddress,
62
+ };
63
+
64
+ const result = await getV1Nfts({
65
+ baseUrl: `https://${getThirdwebDomains().insight}`,
66
+ fetch: getClientFetch(client),
67
+ query: {
68
+ ...defaultQueryOptions,
69
+ ...queryOptions,
70
+ },
71
+ });
72
+
73
+ if (result.error) {
74
+ throw new Error(
75
+ `${result.response.status} ${result.response.statusText} - ${result.error ? stringify(result.error) : "Unknown error"}`,
76
+ );
77
+ }
78
+
79
+ const transformedNfts = await transformNFTModel(
80
+ result.data?.data ?? [],
81
+ client,
82
+ ownerAddress,
83
+ );
84
+ return transformedNfts.map((nft) => ({
85
+ ...nft,
86
+ quantityOwned: nft.quantityOwned ?? 1n,
87
+ }));
88
+ }
89
+
90
+ /**
91
+ * Get all NFTs from a contract
92
+ * @example
93
+ * ```ts
94
+ * import { Insight } from "thirdweb";
95
+ *
96
+ * const nfts = await Insight.getContractNFTs({
97
+ * client,
98
+ * chains: [sepolia],
99
+ * contractAddress: "0x1234567890123456789012345678901234567890",
100
+ * });
101
+ * ```
102
+ * @insight
103
+ */
104
+ export async function getContractNFTs(args: {
105
+ client: ThirdwebClient;
106
+ chains: Chain[];
107
+ contractAddress: string;
108
+ includeMetadata?: boolean;
109
+ includeOwners?: boolean;
110
+ queryOptions?: Omit<GetV1NftsByContractAddressData["query"], "chain">;
111
+ }): Promise<NFT[]> {
112
+ const [
113
+ { getV1NftsByContractAddress },
114
+ { getThirdwebDomains },
115
+ { getClientFetch },
116
+ { assertInsightEnabled },
117
+ { stringify },
118
+ ] = await Promise.all([
119
+ import("@thirdweb-dev/insight"),
120
+ import("../utils/domains.js"),
121
+ import("../utils/fetch.js"),
122
+ import("./common.js"),
123
+ import("../utils/json.js"),
124
+ ]);
125
+
34
126
  const {
35
127
  client,
36
128
  chains,
37
- ownerAddress,
38
- queryOptions = {
39
- chain: chains.map((chain) => chain.id),
40
- metadata: "true",
41
- limit: 100,
42
- page: 1,
129
+ contractAddress,
130
+ includeOwners = true,
131
+ queryOptions,
132
+ } = args;
133
+
134
+ const defaultQueryOptions: GetV1NftsByContractAddressData["query"] = {
135
+ chain: chains.map((chain) => chain.id),
136
+ // metadata: includeMetadata ? "true" : "false", TODO (insight): add support for this
137
+ limit: 50,
138
+ include_owners:
139
+ includeOwners === true ? ("true" as const) : ("false" as const),
140
+ };
141
+
142
+ await assertInsightEnabled(chains);
143
+
144
+ const result = await getV1NftsByContractAddress({
145
+ baseUrl: `https://${getThirdwebDomains().insight}`,
146
+ fetch: getClientFetch(client),
147
+ path: {
148
+ contract_address: contractAddress,
43
149
  },
150
+ query: {
151
+ ...defaultQueryOptions,
152
+ ...queryOptions,
153
+ },
154
+ });
155
+
156
+ if (result.error) {
157
+ throw new Error(
158
+ `${result.response.status} ${result.response.statusText} - ${result.error ? stringify(result.error) : "Unknown error"}`,
159
+ );
160
+ }
161
+
162
+ return transformNFTModel(result.data?.data ?? [], client);
163
+ }
164
+
165
+ /**
166
+ * Get NFT metadata by contract address and token id
167
+ * @example
168
+ * ```ts
169
+ * import { Insight } from "thirdweb";
170
+ *
171
+ * const nft = await Insight.getNFT({
172
+ * client,
173
+ * chain: sepolia,
174
+ * contractAddress: "0x1234567890123456789012345678901234567890",
175
+ * tokenId: 1n,
176
+ * });
177
+ * ```
178
+ * @insight
179
+ */
180
+ export async function getNFT(args: {
181
+ client: ThirdwebClient;
182
+ chain: Chain;
183
+ contractAddress: string;
184
+ tokenId: bigint | number | string;
185
+ includeOwners?: boolean;
186
+ queryOptions?: GetV1NftsByContractAddressByTokenIdData["query"];
187
+ }): Promise<NFT | undefined> {
188
+ const [
189
+ { getV1NftsByContractAddressByTokenId },
190
+ { getThirdwebDomains },
191
+ { getClientFetch },
192
+ { assertInsightEnabled },
193
+ { stringify },
194
+ ] = await Promise.all([
195
+ import("@thirdweb-dev/insight"),
196
+ import("../utils/domains.js"),
197
+ import("../utils/fetch.js"),
198
+ import("./common.js"),
199
+ import("../utils/json.js"),
200
+ ]);
201
+
202
+ const {
203
+ client,
204
+ chain,
205
+ contractAddress,
206
+ tokenId,
207
+ includeOwners = true,
208
+ queryOptions,
44
209
  } = args;
45
210
 
46
- const result = await getV1NftsBalanceByOwnerAddress({
211
+ await assertInsightEnabled([chain]);
212
+
213
+ const defaultQueryOptions: GetV1NftsByContractAddressByTokenIdData["query"] =
214
+ {
215
+ chain: chain.id,
216
+ include_owners:
217
+ includeOwners === true ? ("true" as const) : ("false" as const),
218
+ };
219
+
220
+ const result = await getV1NftsByContractAddressByTokenId({
47
221
  baseUrl: `https://${getThirdwebDomains().insight}`,
48
222
  fetch: getClientFetch(client),
49
223
  path: {
50
- ownerAddress: ownerAddress,
224
+ contract_address: contractAddress,
225
+ token_id: tokenId.toString(),
51
226
  },
52
227
  query: {
53
- chain: chains.map((chain) => chain.id),
228
+ ...defaultQueryOptions,
54
229
  ...queryOptions,
55
230
  },
56
231
  });
@@ -61,5 +236,125 @@ export async function getOwnedNFTs(args: {
61
236
  );
62
237
  }
63
238
 
64
- return result.data?.data ?? [];
239
+ const transformedNfts = await transformNFTModel(
240
+ result.data?.data ?? [],
241
+ client,
242
+ );
243
+ return transformedNfts?.[0];
244
+ }
245
+
246
+ async function transformNFTModel(
247
+ nfts: (ContractNFT | OwnedNFT)[],
248
+ client: ThirdwebClient,
249
+ ownerAddress?: string,
250
+ ): Promise<(NFT & { quantityOwned?: bigint })[]> {
251
+ const [{ parseNFT }, { totalSupply }] = await Promise.all([
252
+ import("../utils/nft/parseNft.js"),
253
+ import("../extensions/erc1155/__generated__/IERC1155/read/totalSupply.js"),
254
+ ]);
255
+
256
+ return await Promise.all(
257
+ nfts.map(async (nft) => {
258
+ let parsedNft: NFT;
259
+ const {
260
+ contract,
261
+ extra_metadata,
262
+ collection,
263
+ metadata_url,
264
+ chain_id,
265
+ token_id,
266
+ status,
267
+ balance,
268
+ token_type,
269
+ ...rest
270
+ } = nft;
271
+ const metadata = replaceIPFSGatewayRecursively({
272
+ uri: nft.metadata_url ?? "",
273
+ image: nft.image_url,
274
+ attributes: nft.extra_metadata?.attributes ?? undefined,
275
+ ...rest,
276
+ });
277
+
278
+ // replace the ipfs gateway with the ipfs gateway from the client recusively for each key in the metadata object
279
+
280
+ const owner_addresses = ownerAddress
281
+ ? [ownerAddress]
282
+ : "owner_addresses" in nft
283
+ ? nft.owner_addresses
284
+ : undefined;
285
+
286
+ if (contract?.type === "erc1155") {
287
+ // TODO (insight): this needs to be added in the API
288
+ const supply = await totalSupply({
289
+ contract: getContract({
290
+ address: contract.address,
291
+ chain: getCachedChain(contract.chain_id),
292
+ client: client,
293
+ }),
294
+ id: BigInt(token_id),
295
+ });
296
+
297
+ parsedNft = parseNFT(metadata, {
298
+ tokenId: BigInt(token_id),
299
+ tokenUri: replaceIPFSGateway(metadata_url) ?? "",
300
+ type: "ERC1155",
301
+ owner: owner_addresses?.[0],
302
+ tokenAddress: contract?.address ?? "",
303
+ chainId: contract?.chain_id ?? 0,
304
+ supply: supply,
305
+ });
306
+ } else {
307
+ parsedNft = parseNFT(metadata, {
308
+ tokenId: BigInt(token_id),
309
+ type: "ERC721",
310
+ owner: owner_addresses?.[0],
311
+ tokenUri: replaceIPFSGateway(metadata_url) ?? "",
312
+ tokenAddress: contract?.address ?? "",
313
+ chainId: contract?.chain_id ?? 0,
314
+ });
315
+ }
316
+
317
+ return parsedNft;
318
+ }),
319
+ );
320
+ }
321
+
322
+ // biome-ignore lint/suspicious/noExplicitAny: this should be fixed in the API
323
+ function replaceIPFSGatewayRecursively(obj: any) {
324
+ if (typeof obj !== "object" || obj === null) {
325
+ return obj;
326
+ }
327
+ for (const key in obj) {
328
+ if (typeof obj[key] === "string") {
329
+ obj[key] = replaceIPFSGateway(obj[key]);
330
+ } else {
331
+ replaceIPFSGatewayRecursively(obj[key]);
332
+ }
333
+ }
334
+ return obj;
335
+ }
336
+
337
+ function replaceIPFSGateway(url?: string) {
338
+ if (!url || typeof url !== "string") {
339
+ return url;
340
+ }
341
+ try {
342
+ const parsedUrl = new URL(url);
343
+ if (parsedUrl.host.endsWith(".ipfscdn.io")) {
344
+ const paths = parsedUrl.pathname.split("/");
345
+ const index = paths.findIndex((path) => path === "ipfs");
346
+ if (index === -1) {
347
+ return url;
348
+ }
349
+ const ipfsHash = paths.slice(index + 1).join("/");
350
+ if (ipfsHash) {
351
+ return `ipfs://${ipfsHash}`;
352
+ }
353
+ return url;
354
+ }
355
+ } catch {
356
+ // If the URL is invalid, return it as is
357
+ return url;
358
+ }
359
+ return url;
65
360
  }
@@ -1,15 +1,12 @@
1
- import {
2
- type GetV1TokensErc20ByOwnerAddressData,
3
- type GetV1TokensErc20ByOwnerAddressResponse,
4
- getV1TokensErc20ByOwnerAddress,
1
+ import type {
2
+ GetV1TokensErc20ByOwnerAddressData,
3
+ GetV1TokensErc20ByOwnerAddressResponse,
5
4
  } from "@thirdweb-dev/insight";
6
- import { stringify } from "viem";
7
5
  import type { Chain } from "../chains/types.js";
8
6
  import type { ThirdwebClient } from "../client/client.js";
9
- import { getThirdwebDomains } from "../utils/domains.js";
10
- import { getClientFetch } from "../utils/fetch.js";
7
+ import type { GetWalletBalanceResult } from "../wallets/utils/getWalletBalance.js";
11
8
 
12
- export type OwnedToken = GetV1TokensErc20ByOwnerAddressResponse["data"][number];
9
+ type OwnedToken = GetV1TokensErc20ByOwnerAddressResponse["data"][number];
13
10
 
14
11
  /**
15
12
  * Get ERC20 tokens owned by an address
@@ -30,19 +27,31 @@ export async function getOwnedTokens(args: {
30
27
  chains: Chain[];
31
28
  ownerAddress: string;
32
29
  queryOptions?: GetV1TokensErc20ByOwnerAddressData["query"];
33
- }): Promise<OwnedToken[]> {
34
- const {
35
- client,
36
- chains,
37
- ownerAddress,
38
- queryOptions = {
39
- chain: chains.map((chain) => chain.id),
40
- include_spam: "false",
41
- metadata: "true",
42
- limit: 100,
43
- page: 1,
44
- },
45
- } = args;
30
+ }): Promise<GetWalletBalanceResult[]> {
31
+ const [
32
+ { getV1TokensErc20ByOwnerAddress },
33
+ { getThirdwebDomains },
34
+ { getClientFetch },
35
+ { assertInsightEnabled },
36
+ { stringify },
37
+ ] = await Promise.all([
38
+ import("@thirdweb-dev/insight"),
39
+ import("../utils/domains.js"),
40
+ import("../utils/fetch.js"),
41
+ import("./common.js"),
42
+ import("../utils/json.js"),
43
+ ]);
44
+
45
+ const { client, chains, ownerAddress, queryOptions } = args;
46
+
47
+ await assertInsightEnabled(chains);
48
+
49
+ const defaultQueryOptions: GetV1TokensErc20ByOwnerAddressData["query"] = {
50
+ chain: chains.map((chain) => chain.id),
51
+ include_spam: "false",
52
+ metadata: "true",
53
+ limit: 50,
54
+ };
46
55
 
47
56
  const result = await getV1TokensErc20ByOwnerAddress({
48
57
  baseUrl: `https://${getThirdwebDomains().insight}`,
@@ -51,7 +60,7 @@ export async function getOwnedTokens(args: {
51
60
  ownerAddress: ownerAddress,
52
61
  },
53
62
  query: {
54
- chain: chains.map((chain) => chain.id),
63
+ ...defaultQueryOptions,
55
64
  ...queryOptions,
56
65
  },
57
66
  });
@@ -62,5 +71,24 @@ export async function getOwnedTokens(args: {
62
71
  );
63
72
  }
64
73
 
65
- return result.data?.data ?? [];
74
+ return transformOwnedToken(result.data?.data ?? []);
75
+ }
76
+
77
+ async function transformOwnedToken(
78
+ token: OwnedToken[],
79
+ ): Promise<GetWalletBalanceResult[]> {
80
+ const { toTokens } = await import("../utils/units.js");
81
+ return token.map((t) => {
82
+ const decimals = t.decimals ?? 18;
83
+ const value = BigInt(t.balance);
84
+ return {
85
+ value,
86
+ displayValue: toTokens(value, decimals),
87
+ tokenAddress: t.token_address,
88
+ chainId: t.chain_id,
89
+ decimals,
90
+ symbol: t.symbol ?? "",
91
+ name: t.name ?? "",
92
+ };
93
+ });
66
94
  }
@@ -1,13 +1,9 @@
1
- import {
2
- type GetV1WalletsByWalletAddressTransactionsData,
3
- type GetV1WalletsByWalletAddressTransactionsResponse,
4
- getV1WalletsByWalletAddressTransactions,
1
+ import type {
2
+ GetV1WalletsByWalletAddressTransactionsData,
3
+ GetV1WalletsByWalletAddressTransactionsResponse,
5
4
  } from "@thirdweb-dev/insight";
6
- import { stringify } from "viem";
7
5
  import type { Chain } from "../chains/types.js";
8
6
  import type { ThirdwebClient } from "../client/client.js";
9
- import { getThirdwebDomains } from "../utils/domains.js";
10
- import { getClientFetch } from "../utils/fetch.js";
11
7
 
12
8
  export type Transaction = NonNullable<
13
9
  GetV1WalletsByWalletAddressTransactionsResponse["data"]
@@ -33,24 +29,38 @@ export async function getTransactions(args: {
33
29
  chains: Chain[];
34
30
  queryOptions?: GetV1WalletsByWalletAddressTransactionsData["query"];
35
31
  }): Promise<Transaction[]> {
32
+ const [
33
+ { getV1WalletsByWalletAddressTransactions },
34
+ { getThirdwebDomains },
35
+ { getClientFetch },
36
+ { assertInsightEnabled },
37
+ { stringify },
38
+ ] = await Promise.all([
39
+ import("@thirdweb-dev/insight"),
40
+ import("../utils/domains.js"),
41
+ import("../utils/fetch.js"),
42
+ import("./common.js"),
43
+ import("../utils/json.js"),
44
+ ]);
45
+
46
+ await assertInsightEnabled(args.chains);
36
47
  const threeMonthsAgoInSeconds = Math.floor(
37
48
  (Date.now() - 3 * 30 * 24 * 60 * 60 * 1000) / 1000,
38
49
  );
39
- const {
40
- client,
41
- walletAddress,
42
- chains,
43
- queryOptions = {
50
+ const { client, walletAddress, chains, queryOptions } = args;
51
+
52
+ const defaultQueryOptions: GetV1WalletsByWalletAddressTransactionsData["query"] =
53
+ {
54
+ chain: chains.map((chain) => chain.id),
44
55
  filter_block_timestamp_gte: threeMonthsAgoInSeconds,
45
56
  limit: 100,
46
- page: 1,
47
- },
48
- } = args;
57
+ };
58
+
49
59
  const result = await getV1WalletsByWalletAddressTransactions({
50
60
  baseUrl: `https://${getThirdwebDomains().insight}`,
51
61
  fetch: getClientFetch(client),
52
62
  query: {
53
- chain: chains.map((chain) => chain.id),
63
+ ...defaultQueryOptions,
54
64
  ...queryOptions,
55
65
  },
56
66
  path: {
@@ -1,4 +1,8 @@
1
- export { getOwnedNFTs, type OwnedNFT } from "./get-nfts.js";
2
- export { getOwnedTokens, type OwnedToken } from "./get-tokens.js";
1
+ export {
2
+ getContractNFTs,
3
+ getOwnedNFTs,
4
+ getNFT,
5
+ } from "./get-nfts.js";
6
+ export { getOwnedTokens } from "./get-tokens.js";
3
7
  export { getTransactions, type Transaction } from "./get-transactions.js";
4
8
  export { getContractEvents, type ContractEvent } from "./get-events.js";