Reading Blockchain Data
Learn how to query data from the Sui blockchain using React hooks and the SuiClient.Query Hooks Overview
The dApp Kit provides React hooks powered by @tanstack/react-query for fetching blockchain data:- useSuiClientQuery - Query any Sui RPC method
- useSuiClientQueries - Query multiple RPC methods in parallel
- useSuiClientInfiniteQuery - Query paginated data with infinite scroll
- useSuiClient - Get the raw SuiClient instance
- ✅ Automatic caching and refetching
- ✅ Loading and error states
- ✅ Type-safe parameters and responses
- ✅ Request deduplication
useSuiClientQuery
The primary hook for querying blockchain data:Syntax
Common Query Examples
Get Owned Objects
Fetch all objects owned by an address:Get SUI Balance
Check the SUI balance of an address:Get All Balances
Get balances for all coin types:Get Object Details
Fetch details of a specific object:Get Transaction Details
Fetch details of a transaction:Query with Filters
Use filters to narrow down results:Pagination with useSuiClientInfiniteQuery
For paginated data like transaction history:Multiple Queries with useSuiClientQueries
Run multiple queries in parallel:Direct Client Access
For advanced use cases, access the SuiClient directly:React Query Options
Customize query behavior with React Query options:Complete Example: NFT Gallery
A complete example showing NFT objects:src/components/NFTGallery.tsx
Next Steps
Now that you can read data from the blockchain, let’s learn how to sign and execute transactions.Sign Transactions
Build, sign, and execute transactions