Skip to content

Commit 8d4d991

Browse files
[SDK] Use insight for erc721/getNFTs and erc721/getOwnedNFTs (#6741)
1 parent 22090cc commit 8d4d991

File tree

48 files changed

+1177
-473
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1177
-473
lines changed

.changeset/purple-bats-march.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Use insight for erc821/getNFT, erc721/getNFTs and erc721/getOwnedNFTs
6+
7+
Standard ERC721 getNFT, getNFTs and getOwnedNFTs now use insight, our in house indexer by default. If indexer is not availbale, will fallback to RPC.
8+
9+
You can also use the indexer directly using the Insight API:
10+
11+
for an entire collection
12+
13+
```ts
14+
import { Insight } from "thirdweb";
15+
16+
const events = await Insight.getContractNFTs({
17+
client,
18+
chains: [sepolia],
19+
contractAddress: "0x1234567890123456789012345678901234567890",
20+
});
21+
```
22+
23+
or for a single NFT
24+
25+
```ts
26+
import { Insight } from "thirdweb";
27+
28+
const events = await Insight.getNFT({
29+
client,
30+
chains: [sepolia],
31+
contractAddress: "0x1234567890123456789012345678901234567890",
32+
tokenId: 1n,
33+
});
34+
```

.github/workflows/CI.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ env:
1616
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
1717
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
1818
TW_SECRET_KEY: ${{ secrets.TW_SECRET_KEY }}
19+
TW_CLIENT_ID: ${{ secrets.TW_CLIENT_ID }}
1920
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
2021

2122
jobs:

apps/dashboard/src/@/actions/getWalletNFTs.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export async function getWalletNFTs(params: {
8181
const result = await transformMoralisResponseToNFT(
8282
await parsedResponse,
8383
owner,
84+
chainId,
8485
);
8586

8687
return { result };
@@ -194,6 +195,8 @@ async function getWalletNFTsFromInsight(params: {
194195
tokenURI: nft.metadata_url,
195196
type: nft.token_type === "erc721" ? "ERC721" : "ERC1155",
196197
supply: nft.balance,
198+
tokenAddress: nft.contract.address,
199+
chainId: nft.contract.chain_id,
197200
};
198201

199202
return walletNFT;

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/(marketplace)/components/list-form.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ export const CreateListingsForm: React.FC<CreateListingsFormProps> = ({
205205
owner: nft.owner,
206206
type: "ERC721",
207207
tokenURI: nft.tokenURI,
208+
chainId: nft.chainId,
209+
tokenAddress: nft.tokenAddress,
208210
};
209211
}
210212
return {
@@ -216,6 +218,8 @@ export const CreateListingsForm: React.FC<CreateListingsFormProps> = ({
216218
owner: nft.owner,
217219
type: "ERC1155",
218220
tokenURI: nft.tokenURI,
221+
chainId: nft.chainId,
222+
tokenAddress: nft.tokenAddress,
219223
};
220224
}) as WalletNFT[];
221225
}, [ownedNFTs, form]);

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/_components/NFTCards.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const dummyMetadata: (idx: number) => NFTWithContract = (idx) => ({
2121
owner: `0x_fake_${idx}`,
2222
type: "ERC721",
2323
supply: 1n,
24+
tokenAddress: ZERO_ADDRESS,
2425
});
2526

2627
interface NFTCardsProps {

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/account/components/nfts-owned.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export const NftsOwned: React.FC<NftsOwnedProps> = ({
3333
type: nft.type,
3434
contractAddress: nft.contractAddress,
3535
chainId: contract.chain.id,
36+
tokenAddress: nft.tokenAddress,
3637
}))}
3738
allNfts
3839
isPending={isWalletNFTsLoading}

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/overview/components/MarketplaceDetails.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { SkeletonContainer } from "@/components/ui/skeleton";
77
import { TrackedLinkTW } from "@/components/ui/tracked-link";
88
import { ArrowRightIcon } from "lucide-react";
99
import { useMemo } from "react";
10-
import type { ThirdwebContract } from "thirdweb";
10+
import { type ThirdwebContract, ZERO_ADDRESS } from "thirdweb";
1111
import {
1212
type DirectListing,
1313
type EnglishAuction,
@@ -237,13 +237,17 @@ const dummyMetadata: (idx: number) => ListingData = (idx) => ({
237237
supply: BigInt(1),
238238
tokenURI: "",
239239
type: "ERC721",
240+
tokenAddress: ZERO_ADDRESS,
241+
chainId: 1,
240242
},
241243
currencyValuePerToken: {
242244
decimals: 18,
243245
displayValue: "0.0",
244246
name: "Ether",
245247
symbol: "ETH",
246248
value: 0n,
249+
tokenAddress: ZERO_ADDRESS,
250+
chainId: 1,
247251
},
248252
creatorAddress: "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef",
249253
type: "direct-listing",
@@ -253,6 +257,8 @@ const dummyMetadata: (idx: number) => ListingData = (idx) => ({
253257
value: 0n,
254258
displayValue: "0.0",
255259
decimals: 18,
260+
tokenAddress: ZERO_ADDRESS,
261+
chainId: 1,
256262
},
257263
});
258264

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/tokens/components/supply.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,15 @@ export const TokenDetailsCard: React.FC<TokenBalancesProps> = ({
4646
tokenSupplyQuery.data,
4747
tokenMetadataQuery.data.decimals,
4848
),
49+
tokenAddress: contract.address,
50+
chainId: contract.chain.id,
4951
};
50-
}, [tokenMetadataQuery.data, tokenSupplyQuery.data]);
52+
}, [
53+
tokenMetadataQuery.data,
54+
tokenSupplyQuery.data,
55+
contract.address,
56+
contract.chain.id,
57+
]);
5158

5259
return (
5360
<TokenDetailsCardUI

apps/dashboard/src/lib/wallet/nfts/moralis.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export function generateMoralisUrl({ chainId, owner }: GenerateURLParams) {
2626
export async function transformMoralisResponseToNFT(
2727
moralisResponse: MoralisResponse,
2828
owner: string,
29+
chainId: number,
2930
): Promise<WalletNFT[]> {
3031
return (
3132
await Promise.all(
@@ -47,6 +48,8 @@ export async function transformMoralisResponseToNFT(
4748
tokenURI: moralisNft.token_uri,
4849
supply: moralisNft.amount || "1",
4950
type: moralisNft.contract_type,
51+
tokenAddress: moralisNft.token_address,
52+
chainId,
5053
} as WalletNFT;
5154
} catch {
5255
return undefined as unknown as WalletNFT;

packages/thirdweb/src/chains/utils.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,9 @@ export function getChainMetadata(chain: Chain): Promise<ChainMetadata> {
296296
`https://api.thirdweb.com/v1/chains/${chainId}`,
297297
);
298298
if (!res.ok) {
299-
res.body?.cancel();
300-
throw new Error(`Failed to fetch chain data for chainId ${chainId}`);
299+
throw new Error(
300+
`Failed to fetch chain data for chainId ${chainId}. ${res.status} ${res.statusText}`,
301+
);
301302
}
302303

303304
const response = (await res.json()) as FetchChainResponse;
@@ -356,8 +357,9 @@ export function getChainServices(chain: Chain): Promise<ChainService[]> {
356357
`https://api.thirdweb.com/v1/chains/${chainId}/services`,
357358
);
358359
if (!res.ok) {
359-
res.body?.cancel();
360-
throw new Error(`Failed to fetch services for chainId ${chainId}`);
360+
throw new Error(
361+
`Failed to fetch services for chainId ${chainId}. ${res.status} ${res.statusText}`,
362+
);
361363
}
362364

363365
const response = (await res.json()) as FetchChainServiceResponse;

0 commit comments

Comments
 (0)