Web SDK
- 概要
- はじめに
- v4からv5への移行
- ガイド
- フック
- useAddFundsModal
- useChain
- useCheckoutModal
- useCheckWaasFeeOptions
- useERC1155SaleContractCheckout
- useGetCoinPrices
- useGetCollectiblePrices
- useListAccounts
- useGetContractInfo
- useGetExchangeRate
- useGetSwapRoutes
- useGetSwapQuote
- useGetTransactionHistory
- useGetMultipleContractsInfo
- useGetTokenMetadata
- useMetadataClient
- useGetNativeTokenBalance
- useGetSingleTokenBalanceSummary
- useGetTransactionHistorySummary
- useIndexerClient
- useGetTokenBalancesByContract
- useGetTokenBalancesDetails
- useGetTokenBalancesSummary
- useIndexerGatewayClient
- useOpenConnectModal
- useOpenWalletModal
- useSelectPaymentModal
- useSignInEmail
- useStorage
- useSwapModal
- useTheme
- useWaasFeeOptions
- useWalletNavigation
- useWalletSettings
- useWallets
- 二次販売マーケットプレイス
- カスタム構成
- カスタムコネクタ
ゲームエンジンSDK
- Unity
- Unreal
その他のSDK
- Typescript
- Go
- モバイル
フック
useGetCoinPrices
トークンリストの現在価格を取得するためのフック
インポート
import { useGetCoinPrices } from '@0xsequence/hooks'
使い方
import { useGetCoinPrices } from '@0xsequence/hooks'
import { ZERO_ADDRESS } from '@0xsequence/hooks'
function TokenPriceDisplay() {
const tokens = [
{
chainId: 1,
contractAddress: ZERO_ADDRESS // ETH
},
{
chainId: 137,
contractAddress: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174' // USDC on Polygon
}
]
const {
data: prices,
isLoading,
error,
isError,
isSuccess
} = useGetCoinPrices(tokens)
if (isLoading) {
return <div>Loading prices...</div>
}
if (isError) {
return <div>Error: {error.message}</div>
}
return (
<div>
<h2>Token Prices</h2>
{isSuccess && prices && (
<ul>
{prices.map((price, index) => (
<li key={`${tokens[index].chainId}-${tokens[index].contractAddress}`}>
Chain {tokens[index].chainId}:{' '}
{price.price.value} {price.price.currency}
</li>
))}
</ul>
)}
</div>
)
}
パラメータ
tokens
Token[]
価格を取得するトークンの配列です。各トークンには以下が必要です。
interface Token {
chainId: number // The chain ID where the token exists
contractAddress: string // The token's contract address
}
ネイティブトークン(例: EthereumのETH、PolygonのMATIC)にはZERO_ADDRESS
を使用してください。
options
HooksOptions
(オプション)
interface HooksOptions {
retry?: boolean // Whether to retry failed requests (defaults to true)
disabled?: boolean // Whether to disable the query
}
返り値の型
このフックはReact Queryの結果オブジェクトを返します:
interface Price {
value: number
currency: string
}
{
data: {
token: Token,
price?: Price,
price24hChange?: Price,
floorPrice?: Price,
buyPrice?: Price,
sellPrice?: Price,
updatedAt: string
}[]
isLoading: boolean // Whether the initial request is in progress
error: Error | null // Any error that occurred
isError: boolean // Whether an error occurred
isSuccess: boolean // Whether the request was successful
}
このページは役に立ちましたか?