VeChain Kit Docs
ResourcesPrivyVeChainChangelog
  • VeChain Kit
    • Intro
    • Quickstart
    • Migrations
      • Migrate from DAppKit
      • Migrate Social Login Users
      • Smart Accounts v1 to v3
    • Troubleshooting
    • Connection Types
    • Send Transactions
    • Sign Messages
    • Text Records (avatar & co.)
    • Hooks
      • Wallet
      • Smart Account
      • Blockchain Hooks
      • Oracle
      • VeBetterDAO
      • veDelegate
      • vetDomains
      • Utils
      • Indexer
      • Ipfs
      • NFTs
      • Transactions
      • Signing
      • Login
    • Components
      • WalletButton
      • Open targeted modals
      • Profile Card
      • Transaction Modal
      • Transaction Toast
  • Configs
  • Utils
  • Social Login
    • Embedded Wallets
    • Smart Accounts
    • Fee Delegation
Powered by GitBook
On this page
  • useGetTokenUsdPrice
  • Parameters
  • Returns
  • Implementation Details
  • Example with Multiple Tokens

Was this helpful?

Edit on GitHub
Export as PDF
  1. VeChain Kit
  2. Hooks

Oracle

useGetTokenUsdPrice

A React hook that fetches the current USD price for supported tokens (B3TR, VET, VTHO) from the VeChain oracle contract.

Usage

import { useGetTokenUsdPrice } from '@vechain/vechain-kit';

function TokenPrice() {
  const { data: vetPrice, isLoading, error } = useGetTokenUsdPrice('VET');
  
  if (isLoading) return <div>Loading...</div>;
  if (error) return <div>Error fetching price</div>;
  
  return <div>VET Price: ${vetPrice}</div>;
}

Parameters

Fetch the price for the following token symbols: 'B3TR', 'VET', 'VTHO'.

Returns

The hook returns a TanStack Query result object with the following properties:

Property
Type
Description

data

number

The current token price in USD.

isLoading

boolean

Indicates if the query is currently loading.

error

Error | null

Describes any error that occurred during query.

isError

boolean

Indicates if there was an error in the query.

Implementation Details

The hook internally:

  • Uses the VeChain oracle contract to fetch real-time price data

  • Automatically handles network configuration (mainnet/testnet)

  • Caches results using TanStack Query

  • Only fetches when both Thor connection and network type are available

Example with Multiple Tokens

function TokenPrices() {
  const { data: vetPrice } = useGetTokenUsdPrice('VET');
  const { data: vthoPrice } = useGetTokenUsdPrice('VTHO');
  const { data: b3trPrice } = useGetTokenUsdPrice('B3TR');

  return (
    <div>
      <div>VET: ${vetPrice}</div>
      <div>VTHO: ${vthoPrice}</div>
      <div>B3TR: ${b3trPrice}</div>
    </div>
  );
}
PreviousBlockchain HooksNextVeBetterDAO

Last updated 3 months ago

Was this helpful?