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.
- package/dist/cjs/extensions/erc1155/read/getNFT.js +38 -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/insight/get-nfts.js +67 -12
- package/dist/cjs/insight/get-nfts.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/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/esm/extensions/erc1155/read/getNFT.js +38 -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/insight/get-nfts.js +67 -12
- package/dist/esm/insight/get-nfts.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/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/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/insight/get-nfts.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/version.d.ts +1 -1
- package/dist/types/wallets/in-app/core/users/getUser.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/extensions/erc1155/read/getNFT.test.ts +11 -0
- package/src/extensions/erc1155/read/getNFT.ts +51 -1
- package/src/extensions/erc1155/read/getNFTs.ts +38 -0
- package/src/extensions/erc1155/read/getOwnedNFTs.ts +65 -2
- package/src/extensions/erc721/read/getNFT.test.ts +81 -83
- package/src/extensions/erc721/read/getNFTs.test.ts +189 -189
- package/src/insight/get-nfts.ts +112 -48
- package/src/rpc/fetch-rpc.ts +2 -20
- package/src/rpc/rpc.ts +5 -1
- 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
@@ -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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
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 () => {
|