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.
- package/dist/cjs/chains/utils.js +2 -4
- package/dist/cjs/chains/utils.js.map +1 -1
- package/dist/cjs/event/actions/get-events.js +4 -10
- package/dist/cjs/event/actions/get-events.js.map +1 -1
- package/dist/cjs/extensions/erc1155/read/getNFT.js +40 -0
- package/dist/cjs/extensions/erc1155/read/getNFT.js.map +1 -1
- package/dist/cjs/extensions/erc1155/read/getNFTs.js +26 -0
- package/dist/cjs/extensions/erc1155/read/getNFTs.js.map +1 -1
- package/dist/cjs/extensions/erc1155/read/getOwnedNFTs.js +46 -0
- package/dist/cjs/extensions/erc1155/read/getOwnedNFTs.js.map +1 -1
- package/dist/cjs/extensions/erc20/read/getBalance.js +2 -0
- package/dist/cjs/extensions/erc20/read/getBalance.js.map +1 -1
- package/dist/cjs/extensions/erc721/read/getNFT.js +42 -0
- package/dist/cjs/extensions/erc721/read/getNFT.js.map +1 -1
- package/dist/cjs/extensions/erc721/read/getNFTs.js +44 -17
- package/dist/cjs/extensions/erc721/read/getNFTs.js.map +1 -1
- package/dist/cjs/extensions/erc721/read/getOwnedNFTs.js +46 -0
- package/dist/cjs/extensions/erc721/read/getOwnedNFTs.js.map +1 -1
- package/dist/cjs/extensions/marketplace/direct-listings/utils.js +7 -4
- package/dist/cjs/extensions/marketplace/direct-listings/utils.js.map +1 -1
- package/dist/cjs/extensions/marketplace/english-auctions/utils.js +9 -4
- package/dist/cjs/extensions/marketplace/english-auctions/utils.js.map +1 -1
- package/dist/cjs/extensions/marketplace/offers/utils.js +7 -4
- package/dist/cjs/extensions/marketplace/offers/utils.js.map +1 -1
- package/dist/cjs/insight/common.js +18 -0
- package/dist/cjs/insight/common.js.map +1 -0
- package/dist/cjs/insight/get-events.js +12 -9
- package/dist/cjs/insight/get-events.js.map +1 -1
- package/dist/cjs/insight/get-nfts.js +213 -16
- package/dist/cjs/insight/get-nfts.js.map +1 -1
- package/dist/cjs/insight/get-tokens.js +34 -14
- package/dist/cjs/insight/get-tokens.js.map +1 -1
- package/dist/cjs/insight/get-transactions.js +17 -12
- package/dist/cjs/insight/get-transactions.js.map +1 -1
- package/dist/cjs/insight/index.js +3 -1
- package/dist/cjs/insight/index.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/ViewNFTs.js +6 -43
- package/dist/cjs/react/web/ui/ConnectWallet/screens/ViewNFTs.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/ViewTokens.js +3 -9
- package/dist/cjs/react/web/ui/ConnectWallet/screens/ViewTokens.js.map +1 -1
- package/dist/cjs/react/web/ui/components/TokenIcon.js +3 -1
- package/dist/cjs/react/web/ui/components/TokenIcon.js.map +1 -1
- package/dist/cjs/react/web/ui/prebuilt/NFT/utils.js +7 -2
- package/dist/cjs/react/web/ui/prebuilt/NFT/utils.js.map +1 -1
- package/dist/cjs/rpc/fetch-rpc.js +2 -22
- package/dist/cjs/rpc/fetch-rpc.js.map +1 -1
- package/dist/cjs/rpc/rpc.js +1 -1
- package/dist/cjs/rpc/rpc.js.map +1 -1
- package/dist/cjs/social/profiles.js +3 -8
- package/dist/cjs/social/profiles.js.map +1 -1
- package/dist/cjs/storage/download.js +2 -2
- package/dist/cjs/storage/download.js.map +1 -1
- package/dist/cjs/storage/unpin.js +2 -2
- package/dist/cjs/storage/unpin.js.map +1 -1
- package/dist/cjs/storage/upload/web-node.js +0 -1
- package/dist/cjs/storage/upload/web-node.js.map +1 -1
- package/dist/cjs/utils/nft/parseNft.js +4 -0
- package/dist/cjs/utils/nft/parseNft.js.map +1 -1
- package/dist/cjs/utils/signatures/resolve-signature.js +0 -2
- package/dist/cjs/utils/signatures/resolve-signature.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/wallets/in-app/core/users/getUser.js +2 -1
- package/dist/cjs/wallets/in-app/core/users/getUser.js.map +1 -1
- package/dist/cjs/wallets/smart/lib/calls.js +2 -2
- package/dist/cjs/wallets/smart/lib/calls.js.map +1 -1
- package/dist/cjs/wallets/utils/getWalletBalance.js +3 -0
- package/dist/cjs/wallets/utils/getWalletBalance.js.map +1 -1
- package/dist/esm/chains/utils.js +2 -4
- package/dist/esm/chains/utils.js.map +1 -1
- package/dist/esm/event/actions/get-events.js +1 -7
- package/dist/esm/event/actions/get-events.js.map +1 -1
- package/dist/esm/extensions/erc1155/read/getNFT.js +40 -0
- package/dist/esm/extensions/erc1155/read/getNFT.js.map +1 -1
- package/dist/esm/extensions/erc1155/read/getNFTs.js +26 -0
- package/dist/esm/extensions/erc1155/read/getNFTs.js.map +1 -1
- package/dist/esm/extensions/erc1155/read/getOwnedNFTs.js +46 -0
- package/dist/esm/extensions/erc1155/read/getOwnedNFTs.js.map +1 -1
- package/dist/esm/extensions/erc20/read/getBalance.js +2 -0
- package/dist/esm/extensions/erc20/read/getBalance.js.map +1 -1
- package/dist/esm/extensions/erc721/read/getNFT.js +42 -0
- package/dist/esm/extensions/erc721/read/getNFT.js.map +1 -1
- package/dist/esm/extensions/erc721/read/getNFTs.js +44 -17
- package/dist/esm/extensions/erc721/read/getNFTs.js.map +1 -1
- package/dist/esm/extensions/erc721/read/getOwnedNFTs.js +46 -0
- package/dist/esm/extensions/erc721/read/getOwnedNFTs.js.map +1 -1
- package/dist/esm/extensions/marketplace/direct-listings/utils.js +7 -4
- package/dist/esm/extensions/marketplace/direct-listings/utils.js.map +1 -1
- package/dist/esm/extensions/marketplace/english-auctions/utils.js +9 -4
- package/dist/esm/extensions/marketplace/english-auctions/utils.js.map +1 -1
- package/dist/esm/extensions/marketplace/offers/utils.js +7 -4
- package/dist/esm/extensions/marketplace/offers/utils.js.map +1 -1
- package/dist/esm/insight/common.js +15 -0
- package/dist/esm/insight/common.js.map +1 -0
- package/dist/esm/insight/get-events.js +8 -5
- package/dist/esm/insight/get-events.js.map +1 -1
- package/dist/esm/insight/get-nfts.js +208 -13
- package/dist/esm/insight/get-nfts.js.map +1 -1
- package/dist/esm/insight/get-tokens.js +30 -10
- package/dist/esm/insight/get-tokens.js.map +1 -1
- package/dist/esm/insight/get-transactions.js +13 -8
- package/dist/esm/insight/get-transactions.js.map +1 -1
- package/dist/esm/insight/index.js +1 -1
- package/dist/esm/insight/index.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/ViewNFTs.js +6 -43
- package/dist/esm/react/web/ui/ConnectWallet/screens/ViewNFTs.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/ViewTokens.js +3 -9
- package/dist/esm/react/web/ui/ConnectWallet/screens/ViewTokens.js.map +1 -1
- package/dist/esm/react/web/ui/components/TokenIcon.js +3 -1
- package/dist/esm/react/web/ui/components/TokenIcon.js.map +1 -1
- package/dist/esm/react/web/ui/prebuilt/NFT/utils.js +7 -2
- package/dist/esm/react/web/ui/prebuilt/NFT/utils.js.map +1 -1
- package/dist/esm/rpc/fetch-rpc.js +2 -22
- package/dist/esm/rpc/fetch-rpc.js.map +1 -1
- package/dist/esm/rpc/rpc.js +1 -1
- package/dist/esm/rpc/rpc.js.map +1 -1
- package/dist/esm/social/profiles.js +3 -8
- package/dist/esm/social/profiles.js.map +1 -1
- package/dist/esm/storage/download.js +2 -2
- package/dist/esm/storage/download.js.map +1 -1
- package/dist/esm/storage/unpin.js +2 -2
- package/dist/esm/storage/unpin.js.map +1 -1
- package/dist/esm/storage/upload/web-node.js +0 -1
- package/dist/esm/storage/upload/web-node.js.map +1 -1
- package/dist/esm/utils/nft/parseNft.js +4 -0
- package/dist/esm/utils/nft/parseNft.js.map +1 -1
- package/dist/esm/utils/signatures/resolve-signature.js +0 -2
- package/dist/esm/utils/signatures/resolve-signature.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/wallets/in-app/core/users/getUser.js +2 -1
- package/dist/esm/wallets/in-app/core/users/getUser.js.map +1 -1
- package/dist/esm/wallets/smart/lib/calls.js +2 -2
- package/dist/esm/wallets/smart/lib/calls.js.map +1 -1
- package/dist/esm/wallets/utils/getWalletBalance.js +3 -0
- package/dist/esm/wallets/utils/getWalletBalance.js.map +1 -1
- package/dist/types/chains/utils.d.ts.map +1 -1
- package/dist/types/event/actions/get-events.d.ts.map +1 -1
- package/dist/types/extensions/erc1155/read/getNFT.d.ts +5 -0
- package/dist/types/extensions/erc1155/read/getNFT.d.ts.map +1 -1
- package/dist/types/extensions/erc1155/read/getNFTs.d.ts +5 -0
- package/dist/types/extensions/erc1155/read/getNFTs.d.ts.map +1 -1
- package/dist/types/extensions/erc1155/read/getOwnedNFTs.d.ts +7 -1
- package/dist/types/extensions/erc1155/read/getOwnedNFTs.d.ts.map +1 -1
- package/dist/types/extensions/erc20/read/getBalance.d.ts +2 -0
- package/dist/types/extensions/erc20/read/getBalance.d.ts.map +1 -1
- package/dist/types/extensions/erc721/read/getNFT.d.ts +5 -0
- package/dist/types/extensions/erc721/read/getNFT.d.ts.map +1 -1
- package/dist/types/extensions/erc721/read/getNFTs.d.ts +5 -0
- package/dist/types/extensions/erc721/read/getNFTs.d.ts.map +1 -1
- package/dist/types/extensions/erc721/read/getOwnedNFTs.d.ts +3 -1
- package/dist/types/extensions/erc721/read/getOwnedNFTs.d.ts.map +1 -1
- package/dist/types/extensions/marketplace/direct-listings/utils.d.ts.map +1 -1
- package/dist/types/extensions/marketplace/english-auctions/utils.d.ts.map +1 -1
- package/dist/types/extensions/marketplace/offers/utils.d.ts.map +1 -1
- package/dist/types/insight/common.d.ts +3 -0
- package/dist/types/insight/common.d.ts.map +1 -0
- package/dist/types/insight/get-events.d.ts +2 -2
- package/dist/types/insight/get-events.d.ts.map +1 -1
- package/dist/types/insight/get-nfts.d.ts +52 -4
- package/dist/types/insight/get-nfts.d.ts.map +1 -1
- package/dist/types/insight/get-tokens.d.ts +3 -3
- package/dist/types/insight/get-tokens.d.ts.map +1 -1
- package/dist/types/insight/get-transactions.d.ts +1 -1
- package/dist/types/insight/get-transactions.d.ts.map +1 -1
- package/dist/types/insight/index.d.ts +2 -2
- package/dist/types/insight/index.d.ts.map +1 -1
- package/dist/types/react/core/utils/wallet.d.ts +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.d.ts +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/ViewNFTs.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/ViewTokens.d.ts.map +1 -1
- package/dist/types/react/web/ui/components/TokenIcon.d.ts.map +1 -1
- package/dist/types/react/web/ui/prebuilt/NFT/utils.d.ts.map +1 -1
- package/dist/types/rpc/fetch-rpc.d.ts.map +1 -1
- package/dist/types/rpc/rpc.d.ts.map +1 -1
- package/dist/types/social/profiles.d.ts.map +1 -1
- package/dist/types/storage/download.d.ts.map +1 -1
- package/dist/types/storage/unpin.d.ts.map +1 -1
- package/dist/types/storage/upload/web-node.d.ts.map +1 -1
- package/dist/types/utils/nft/parseNft.d.ts +8 -0
- package/dist/types/utils/nft/parseNft.d.ts.map +1 -1
- package/dist/types/utils/signatures/resolve-signature.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/wallets/in-app/core/users/getUser.d.ts.map +1 -1
- package/dist/types/wallets/utils/getWalletBalance.d.ts +2 -7
- package/dist/types/wallets/utils/getWalletBalance.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/chains/utils.ts +6 -4
- package/src/event/actions/get-events.ts +1 -13
- package/src/extensions/erc1155/read/getNFT.test.ts +13 -0
- package/src/extensions/erc1155/read/getNFT.ts +53 -1
- package/src/extensions/erc1155/read/getNFTs.ts +38 -0
- package/src/extensions/erc1155/read/getOwnedNFTs.ts +65 -2
- package/src/extensions/erc20/drop20.test.ts +48 -132
- package/src/extensions/erc20/read/getBalance.test.ts +5 -9
- package/src/extensions/erc20/read/getBalance.ts +4 -0
- package/src/extensions/erc721/read/getNFT.test.ts +106 -0
- package/src/extensions/erc721/read/getNFT.ts +55 -1
- package/src/extensions/erc721/read/getNFTs.test.ts +212 -6
- package/src/extensions/erc721/read/getNFTs.ts +59 -20
- package/src/extensions/erc721/read/getOwnedNFTs.test.ts +27 -2
- package/src/extensions/erc721/read/getOwnedNFTs.ts +61 -1
- package/src/extensions/erc721/token721.test.ts +2 -0
- package/src/extensions/marketplace/direct-listings/direct-listings.test.ts +2 -18
- package/src/extensions/marketplace/direct-listings/utils.ts +7 -4
- package/src/extensions/marketplace/english-auctions/utils.ts +9 -4
- package/src/extensions/marketplace/offers/utils.ts +7 -4
- package/src/insight/common.ts +24 -0
- package/src/insight/get-events.ts +23 -9
- package/src/insight/get-nfts.ts +315 -20
- package/src/insight/get-tokens.ts +51 -23
- package/src/insight/get-transactions.ts +26 -16
- package/src/insight/index.ts +6 -2
- package/src/react/web/ui/ConnectWallet/screens/ViewNFTs.tsx +43 -68
- package/src/react/web/ui/ConnectWallet/screens/ViewTokens.tsx +4 -14
- package/src/react/web/ui/components/TokenIcon.tsx +12 -3
- package/src/react/web/ui/prebuilt/NFT/utils.test.ts +2 -64
- package/src/react/web/ui/prebuilt/NFT/utils.ts +7 -2
- package/src/rpc/fetch-rpc.ts +2 -20
- package/src/rpc/rpc.ts +5 -1
- package/src/social/profiles.ts +5 -9
- package/src/storage/download.ts +4 -2
- package/src/storage/unpin.ts +4 -2
- package/src/storage/upload/web-node.ts +0 -1
- package/src/utils/nft/parseNft.test.ts +8 -0
- package/src/utils/nft/parseNft.ts +12 -0
- package/src/utils/signatures/resolve-signature.ts +0 -2
- package/src/version.ts +1 -1
- package/src/wallets/in-app/core/users/getUser.test.ts +4 -1
- package/src/wallets/in-app/core/users/getUser.ts +4 -1
- package/src/wallets/smart/lib/calls.ts +2 -2
- 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
|
-
|
3
|
-
|
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?:
|
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
|
},
|
package/src/insight/get-nfts.ts
CHANGED
@@ -1,15 +1,18 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
|
4
|
-
|
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 {
|
10
|
-
import { getClientFetch } from "../utils/fetch.js";
|
10
|
+
import type { NFT } from "../utils/nft/parseNft.js";
|
11
11
|
|
12
|
-
|
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
|
-
|
33
|
-
|
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
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
-
|
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
|
-
|
224
|
+
contract_address: contractAddress,
|
225
|
+
token_id: tokenId.toString(),
|
51
226
|
},
|
52
227
|
query: {
|
53
|
-
|
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
|
-
|
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
|
-
|
3
|
-
|
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 {
|
10
|
-
import { getClientFetch } from "../utils/fetch.js";
|
7
|
+
import type { GetWalletBalanceResult } from "../wallets/utils/getWalletBalance.js";
|
11
8
|
|
12
|
-
|
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<
|
34
|
-
const
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
-
|
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
|
-
|
3
|
-
|
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
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
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
|
-
|
63
|
+
...defaultQueryOptions,
|
54
64
|
...queryOptions,
|
55
65
|
},
|
56
66
|
path: {
|
package/src/insight/index.ts
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
-
export {
|
2
|
-
|
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";
|