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
  • Common Features
  • Query Invalidation
  • Caching Behavior

Was this helpful?

Edit on GitHub
Export as PDF
  1. VeChain Kit

Hooks

PreviousText Records (avatar & co.)NextWallet

Last updated 2 months ago

Was this helpful?

The kit provides hooks for developers to interact with smart contracts like VeBetterDAO, VePassport, veDelegate, and price oracles.

The hooks in this package provide a standardized way to interact with various blockchain and web services. All hooks are built using (formerly React Query), which provides powerful data-fetching and caching capabilities.

Common Features

Every hook in the @api directory returns a consistent interface that includes:

  • data: The fetched data

  • isLoading: Boolean indicating if the request is in progress

  • isError: Boolean indicating if the request failed

  • error: Error object if the request failed

  • refetch: Function to manually trigger a new fetch

  • isRefetching: Boolean indicating if a refetch is in progress

Additionally, these hooks integrate with TanStack Query's global features:

  • Automatic background refetching

  • Cache invalidation

  • Optimistic updates

  • Infinite queries (for pagination)

  • Parallel queries

  • Query retrying

  • Query polling

Query Invalidation

All hooks use consistent query key patterns, making it easy to invalidate related queries. For example:

const queryClient = useQueryClient();
// Invalidate all blockchain queries
queryClient.invalidateQueries({ queryKey: ['VECHAIN_KIT'] });
// Invalidate specific query
queryClient.invalidateQueries({ queryKey: ['VECHAIN_KIT', 'CURRENT_BLOCK'] });

Caching Behavior

By default, most queries are configured with:

  • staleTime: How long the data remains "fresh"

  • cacheTime: How long inactive data remains in cache

  • refetchInterval: For automatic background updates (if applicable)

These can be customized using TanStack Query's global configuration or per-hook options.

TanStack Query