|
| 1 | +This hook fetches data found on the blockchain from the given zNFT. The only argument for the hook is the NFT id. To fetch data for zNFTs on other networks, use the `NFTFetchConfiguration` wrapper component to set the correct network for loading the NFT data. |
| 2 | +The main types are within the result `data.nft` object. This object contains the on-chain NFT data itself. The pricing information can be found in `data.pricing` which corresponds to data on-chain for Zora's perpetual zNFT auctions along with the reserve auction functionality. |
| 3 | + |
| 4 | +```ts |
| 5 | +import {useNFT} from "@zoralabs/nft-hooks"; |
| 6 | + |
| 7 | +type NFTDataType = { |
| 8 | + nft: { |
| 9 | + id: string, // ID of zNFT |
| 10 | + owner: {id: string}, // Address of owner |
| 11 | + creator: {id: string}, // Address of creator |
| 12 | + metadataURI: string, // URI of metadata for zNFT |
| 13 | + metadataHash: string, // sha256 hash for metadata for zNFT |
| 14 | + contentURI: string, // URI of content described by metadata |
| 15 | + contentHash: string, // sha256 hash of content |
| 16 | + }, |
| 17 | + |
| 18 | + pricing: { |
| 19 | + perpetual: { |
| 20 | + bids: { // empty array if no bids |
| 21 | + id: string; |
| 22 | + createdAtTimestamp: string; |
| 23 | + bidder: { id: string }; |
| 24 | + pricing: PricingInfo; |
| 25 | + }[], |
| 26 | + ask?: { |
| 27 | + id: string, |
| 28 | + createdAtTimestamp: string; |
| 29 | + pricing: PricingInfo; |
| 30 | + }; |
| 31 | + }, |
| 32 | + reserve?: { |
| 33 | + auctionCurrency: CurrencyInformation; |
| 34 | + id: string; |
| 35 | + tokenId: string; |
| 36 | + status: "Pending" | "Active" | "Canceled" | "Finished"; |
| 37 | + firstBidTime: string; |
| 38 | + duration: string; |
| 39 | + expectedEndTimestamp: string; |
| 40 | + createdAtTimestamp: string; |
| 41 | + finalizedAtTimestamp: string; |
| 42 | + }, |
| 43 | + }; |
| 44 | + |
| 45 | + // Current/ongoing auction information synthesized from pricing data |
| 46 | + auction: { |
| 47 | + highestBid: { |
| 48 | + pricing: PricingInfo; |
| 49 | + placedBy: string; |
| 50 | + placedAt: string; |
| 51 | + }; |
| 52 | + current: { |
| 53 | + auctionType: "reserve" | "perpetual"; |
| 54 | + endingAt?: string; |
| 55 | + likelyHasEnded: boolean; // If an auction ended but has not been finalized this will be true. |
| 56 | + reserveMet: boolean; |
| 57 | + reservePrice?: PricingInfo; |
| 58 | + }; |
| 59 | + }; |
| 60 | +}; |
| 61 | + |
| 62 | +export type PricingInfo = { |
| 63 | + currency: CurrencyInformation; |
| 64 | + amount: string; // Amount as raw bignumber |
| 65 | + prettyAmount: string; // Amount as a normalized BigDecimal value |
| 66 | + computedValue?: PricingInfoValue; // Computed value in USD and ETH (available from Uniswap API call) |
| 67 | +}; |
| 68 | + |
| 69 | +type CurrencyInformation = { |
| 70 | + id: string, // Blockchain address of currency. If ETH currency, will be 0x0000000000000000000000000000000000000000 |
| 71 | + name: string, // Name of currency |
| 72 | + symbol: string, // Symbol of currency |
| 73 | + decimals: number, // Decimals for currency |
| 74 | +}; |
| 75 | + |
| 76 | + |
| 77 | +type useNFT = (id: string) => { |
| 78 | + loading: boolean; |
| 79 | + error?: string; // undefined if no error, string if error |
| 80 | + chainNFT?: NFTDataType; // undefined in error or loading states |
| 81 | +} |
| 82 | + |
| 83 | +// Example with usage: |
| 84 | +const {chainNFT, loading} = useNFT("2"); |
| 85 | +``` |
| 86 | + |
| 87 | +Alternatively, the same information can be fetched using the base MediaFetchAgentfor server-side or non-react use: |
| 88 | + |
| 89 | +```ts |
| 90 | +import {MediaFetchAgent, Networks} from "@zoralabs/nft-hooks"; |
| 91 | + |
| 92 | +// Be careful making multiple instances of the fetch agent |
| 93 | +// Each instance contains a different request cache. |
| 94 | +const fetchAgent = new MediaFetchAgent(Networks.MAINNET); |
| 95 | + |
| 96 | +// Get result from the server |
| 97 | +const result = await fetchAgent.loadNFTData("2"); |
| 98 | +// result type is NFTDataType |
| 99 | +``` |
0 commit comments