diff --git a/packages/sdk/src/core/schema/QueryParams.ts b/packages/sdk/src/core/schema/QueryParams.ts index f592c259946..333821c04e9 100644 --- a/packages/sdk/src/core/schema/QueryParams.ts +++ b/packages/sdk/src/core/schema/QueryParams.ts @@ -10,10 +10,12 @@ export const QueryAllParamsSchema = /* @__PURE__ */ (() => .object({ start: z.number().default(0), count: z.number().default(DEFAULT_QUERY_ALL_COUNT), + loadMetadata: z.boolean().default(true), }) .default({ start: 0, count: DEFAULT_QUERY_ALL_COUNT, + loadMetadata: true, }))(); /** diff --git a/packages/sdk/src/core/schema/nft.ts b/packages/sdk/src/core/schema/nft.ts index d4b01b09eb9..23853a479bc 100644 --- a/packages/sdk/src/core/schema/nft.ts +++ b/packages/sdk/src/core/schema/nft.ts @@ -76,3 +76,13 @@ export type NFT = { supply: string; quantityOwned?: string; }; +/** + * @public + */ +export type NFTWithoutMetadata = { + metadata: Pick; + owner: string; + type: "ERC1155" | "ERC721" | "metaplex"; + supply: string; + quantityOwned?: string; +}; diff --git a/packages/sdk/src/evm/core/classes/erc-721.ts b/packages/sdk/src/evm/core/classes/erc-721.ts index 40e619fafce..a347aed6531 100644 --- a/packages/sdk/src/evm/core/classes/erc-721.ts +++ b/packages/sdk/src/evm/core/classes/erc-721.ts @@ -25,6 +25,7 @@ import type { NFT, NFTMetadata, NFTMetadataOrUri, + NFTWithoutMetadata, } from "../../../core/schema/nft"; import { resolveAddress } from "../../common/ens/resolveAddress"; import { @@ -167,16 +168,34 @@ export class Erc721< * @returns The NFT metadata * @twfeature ERC721 */ - public async get(tokenId: BigNumberish): Promise { - const [owner, metadata] = await Promise.all([ - this.ownerOf(tokenId).catch(() => constants.AddressZero), - this.getTokenMetadata(tokenId).catch(() => ({ - id: tokenId.toString(), - uri: "", - ...FALLBACK_METADATA, - })), - ]); - return { owner, metadata, type: "ERC721", supply: "1" }; + public async get( + tokenId: BigNumberish, + loadMetadata?: T, + ): Promise { + if (loadMetadata === false) { + const owner = await this.ownerOf(tokenId).catch( + () => constants.AddressZero, + ); + const nft: NFTWithoutMetadata = { + owner, + metadata: { + id: tokenId.toString(), + }, + type: "ERC721", + supply: "1", + }; + return nft as T extends true | undefined ? NFT : NFTWithoutMetadata; + } else { + const [owner, metadata] = await Promise.all([ + this.ownerOf(tokenId).catch(() => constants.AddressZero), + this.getTokenMetadata(tokenId).catch(() => ({ + id: tokenId.toString(), + uri: "", + ...FALLBACK_METADATA, + })), + ]); + return { owner, metadata, type: "ERC721", supply: "1" }; + } } /** @@ -425,11 +444,10 @@ export class Erc721< public async getOwned( walletAddress?: AddressOrEns, queryParams?: QueryAllParams, - ) { + ): Promise { if (walletAddress) { walletAddress = await resolveAddress(walletAddress); } - if (this.query?.owned) { return this.query.owned.all(walletAddress, queryParams); } else { @@ -445,8 +463,11 @@ export class Erc721< const count = queryParams?.count || DEFAULT_QUERY_ALL_COUNT; ownedTokens = ownedTokens.slice(start, start + count); } + const loadMetadata = queryParams + ? queryParams.loadMetadata !== false + : true; return await Promise.all( - ownedTokens.map(async (i) => this.get(i.tokenId)), + ownedTokens.map(async (i) => this.get(i.tokenId, loadMetadata)), ); } } diff --git a/packages/sdk/src/index.ts b/packages/sdk/src/index.ts index cc462d0ceea..84813dc9d8f 100644 --- a/packages/sdk/src/index.ts +++ b/packages/sdk/src/index.ts @@ -9,6 +9,7 @@ export type { NFTMetadata, NFTMetadataOrUri, BasicNFTInput, + NFTWithoutMetadata, } from "./core/schema/nft"; export type { CurrencyValue, TokenMetadata } from "./core/schema/token";