|
| 1 | +--- |
| 2 | +title: useGetCollectiblePrices |
| 3 | +description: Hook para obtener precios de mercado actuales de NFTs/coleccionables |
| 4 | +sidebarTitle: useGetCollectiblePrices |
| 5 | +--- |
| 6 | + |
| 7 | +## Importar |
| 8 | + |
| 9 | +```tsx |
| 10 | +import { useGetCollectiblePrices } from '@0xsequence/hooks' |
| 11 | +``` |
| 12 | + |
| 13 | +## Uso |
| 14 | + |
| 15 | +```tsx |
| 16 | +import { useGetCollectiblePrices } from '@0xsequence/hooks' |
| 17 | + |
| 18 | +function NFTPriceDisplay() { |
| 19 | + const tokens = [ |
| 20 | + { |
| 21 | + chainId: 1, |
| 22 | + contractAddress: '0x34d85c9CDeB23FA97cb08333b511ac86E1C4E258', // Example NFT collection |
| 23 | + tokenId: '123' |
| 24 | + } |
| 25 | + ] |
| 26 | + |
| 27 | + const { |
| 28 | + data: prices, |
| 29 | + isLoading, |
| 30 | + error, |
| 31 | + isError, |
| 32 | + isSuccess |
| 33 | + } = useGetCollectiblePrices(tokens) |
| 34 | + |
| 35 | + if (isLoading) { |
| 36 | + return <div>Loading prices...</div> |
| 37 | + } |
| 38 | + |
| 39 | + if (isError) { |
| 40 | + return <div>Error: {error.message}</div> |
| 41 | + } |
| 42 | + |
| 43 | + return ( |
| 44 | + <div> |
| 45 | + <h2>NFT Prices</h2> |
| 46 | + {isSuccess && prices && ( |
| 47 | + <ul> |
| 48 | + {prices.map((price, index) => ( |
| 49 | + <li key={`${tokens[index].chainId}-${tokens[index].contractAddress}-${tokens[index].tokenId}`}> |
| 50 | + <div>Collection: {tokens[index].contractAddress}</div> |
| 51 | + <div>Token ID: {tokens[index].tokenId}</div> |
| 52 | + <div>Floor Price: {price.floorPrice.value} {price.floorPrice.currency}</div> |
| 53 | + <div>Buy Price: {price.buyPrice.value} {price.buyPrice.currency}</div> |
| 54 | + <div>Sell Price: {price.sellPrice.value} {price.sellPrice.currency}</div> |
| 55 | + </li> |
| 56 | + ))} |
| 57 | + </ul> |
| 58 | + )} |
| 59 | + </div> |
| 60 | + ) |
| 61 | +} |
| 62 | +``` |
| 63 | + |
| 64 | +### tokens |
| 65 | +`Token[]`: Arreglo de objetos con `chainId` y `contractAddress` que representan los tokens para los cuales desea obtener el precio. |
| 66 | + |
| 67 | +```tsx |
| 68 | +interface Token { |
| 69 | + chainId: number // EVM chain ID (e.g., 1 = Ethereum, 137 = Polygon) |
| 70 | + contractAddress: string // Token contract address on that chain |
| 71 | + tokenId: string // The specific token ID within the collection |
| 72 | +} |
| 73 | +``` |
| 74 | + |
| 75 | +### options |
| 76 | +`HooksOptions` (opcional) |
| 77 | + |
| 78 | +```tsx |
| 79 | +interface HooksOptions { |
| 80 | + retry?: boolean // Whether to retry failed requests (defaults to true) |
| 81 | + disabled?: boolean // Whether to disable the query |
| 82 | +} |
| 83 | +``` |
| 84 | + |
| 85 | +## Tipo de retorno |
| 86 | +El hook retorna un objeto resultado de React Query: |
| 87 | + |
| 88 | +```tsx |
| 89 | +interface Price { |
| 90 | + value: number |
| 91 | + currency: string |
| 92 | +} |
| 93 | + |
| 94 | +{ |
| 95 | + data: { |
| 96 | + token: Token, |
| 97 | + price?: Price, |
| 98 | + price24hChange?: Price, |
| 99 | + floorPrice?: Price, |
| 100 | + buyPrice?: Price, |
| 101 | + sellPrice?: Price, |
| 102 | + updatedAt: string |
| 103 | + }[] |
| 104 | + isLoading: boolean // Whether the initial request is in progress |
| 105 | + error: Error | null // Any error that occurred |
| 106 | + isError: boolean // Whether an error occurred |
| 107 | + isSuccess: boolean // Whether the request was successful |
| 108 | +} |
| 109 | +``` |
0 commit comments