diff --git a/README.md b/README.md index 1da3037..9e72338 100644 --- a/README.md +++ b/README.md @@ -340,18 +340,44 @@ An object with the following fields: - `owner`: The address that you want to fetch NFTs for. - `pageKey`: (Optional) A key to fetch the next page of results. - `contractAddresses`: (Optional) An array of contract addresses to filter the owner's results to. +- `withMetadata`: (Optional) If `false`, the returned NFTs will omit metadata. Defaults to `true`. **Returns:** -An object with the following fields: +When metadata is included, the returned object has the following fields: + +- `ownedNfts`: An array of NFT objects that the address owns. Each NFT object has the following structure. + - `contract`: + - `address`: The address of the contract or collection that the NFT belongs to. + - `id`: + - `tokenId`: Raw token id. + - `tokenMetadata`: + - `tokenType`: The type of token being sent as part of the request (Can be one of ["erc721" | "erc1155"]). + - `title`: The title of the NFT, or an empty string if no title is available. + - `description`: The descriptions of the NFT, or an empty string if no description is available. + - `tokenUri`: (Optional) + - `raw`: Uri representing the location of the NFT's original metadata blob. This is a backup for you to parse + when the `metadata` field is not automatically populated. + - `gateway`: Public gateway uri for the raw uri. + - `media`: (Optional) An array of objects with the following structure. + - `uri`: A `tokenUri` as described above. + - `metadata`: (Optional) + - `image`: (Optional) A uri string that should be usable in an tag. + - `attributes`: (Optional) An array of attributes from the NFT metadata. Each attribute is a dictionary with + unknown keys and values, as they depend directly on the contract. + - `timeLastUpdated`: ISO timestamp of the last cache refresh for the information returned in the metadata field. +- `pageKey`: (Optional) A key to fetch the next page of results, if applicable. +- `totalCount`: The total number of NFTs in the result set. + +If metadata is omitted, an object with the following fields is returned: - `ownedNfts`: An array of NFT objects that the address owns. Each NFT object has the following structure. - - `contract`: - - `address`: The address of the contract or collection that the NFT belongs to. - - `id`: - - `tokenId`: Raw token id. - - `tokenMetadata`: - - `tokenType`: The type of token being sent as part of the request (Can be one of ["erc721" | "erc1155"]). + - `contract`: + - `address`: The address of the contract or collection that the NFT belongs to. + - `id`: + - `tokenId`: Raw token id. + - `tokenMetadata`: + - `tokenType`: The type of token being sent as part of the request (Can be one of ["erc721" | "erc1155"]). - `pageKey`: (Optional) A key to fetch the next page of results, if applicable. - `totalCount`: The total number of NFTs in the result set. diff --git a/src/alchemy-apis/types.ts b/src/alchemy-apis/types.ts index 63b34f6..2922d60 100644 --- a/src/alchemy-apis/types.ts +++ b/src/alchemy-apis/types.ts @@ -79,7 +79,9 @@ export interface AssetTransfersResult { rawContract: RawContract; } -export interface NftMetadata { +export interface NftMetadata extends Record { + name?: string; + description?: string; image?: string; attributes?: Array>; } @@ -112,9 +114,9 @@ export interface GetNftMetadataParams { tokenType?: "erc721" | "erc1155"; } -export interface GetNftMetadataResponse { - contract: NftContract; - id: NftId; +export type GetNftMetadataResponse = NftMetadata; + +export interface Nft extends BaseNft { title: string; description: string; tokenUri?: TokenUri; @@ -123,10 +125,23 @@ export interface GetNftMetadataResponse { timeLastUpdated: string; } +export interface BaseNft { + contract: NftContract; + id: NftId; +} + export interface GetNftsParams { owner: string; pageKey?: string; contractAddresses?: string[]; + withMetadata?: boolean; +} + +export interface GetNftsParamsWithoutMetadata { + owner: string; + pageKey?: string; + contractAddresses?: string[]; + withMetadata: false; } export interface GetNftsResponse { @@ -135,6 +150,12 @@ export interface GetNftsResponse { totalCount: number; } +export interface GetNftsResponseWithoutMetadata { + ownedNfts: BaseNft[]; + pageKey?: string; + totalCount: number; +} + export interface TransactionReceiptsBlockNumber { blockNumber: string; } @@ -179,11 +200,6 @@ export interface Log { transactionIndex: string; } -export interface Nft { - contract: NftContract; - id: NftId; -} - export interface ERC1155Metadata { tokenId: string; value: string; diff --git a/src/index.ts b/src/index.ts index b8f436b..10f9925 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,7 +10,9 @@ import { GetNftMetadataParams, GetNftMetadataResponse, GetNftsParams, + GetNftsParamsWithoutMetadata, GetNftsResponse, + GetNftsResponseWithoutMetadata, TokenAllowanceParams, TokenAllowanceResponse, TokenBalancesResponse, @@ -70,9 +72,13 @@ export interface AlchemyMethods { callback?: Web3Callback, ): Promise; getNfts( - params: GetNftsParams, - callback?: Web3Callback, - ): Promise; + params: GetNftsParams | GetNftsParamsWithoutMetadata, + callback?: Web3Callback, + ): Promise; + getNfts( + params: GetNftsParamsWithoutMetadata, + callback?: Web3Callback, + ): Promise; getTransactionReceipts( params: TransactionReceiptsParams, callback?: Web3Callback, @@ -194,7 +200,7 @@ export function createAlchemyWeb3( params, path: "/v1/getNFTMetadata/", }), - getNfts: (params: GetNftsParams, callback) => + getNfts: (params: GetNftsParams | GetNftsParamsWithoutMetadata, callback) => callAlchemyRestEndpoint({ restSender, callback,