@coin-communities/sdk/react-query ships hook bindings around every operation in the SDK Reference, plus a queryKeys factory for cache invalidation and prefetching. The entry also re-exports configureApi and the api namespace, so it's the only import path most React apps need.
@tanstack/react-query (v5+) is a peer dependency.
Setup
bun add @coin-communities/sdk @tanstack/react-query
Wrap your app in a QueryClientProvider and configure the SDK once at boot:
import { configureApi } from '@coin-communities/sdk/react-query';import { QueryClient, QueryClientProvider } from '@tanstack/react-query';configureApi({ baseUrl: 'https://api.coin-communities.xyz', auth: () => getToken(),});const queryClient = new QueryClient();export function App({ children }: { children: React.ReactNode }) { return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>;}
Conventions
Read operations (GET) are exposed as useXxx() hooks returning UseQueryResult<TData, TError>.
Write operations (POST / PUT / DELETE) are exposed as useXxx() hooks returning UseMutationResult<TData, TError, TVars>.
Hooks accept the standard React Query options object as their last argument (onSuccess, onError, select, enabled, …) — query/mutation keys and functions are managed for you.
Mutations that target a single resource (e.g. useRotateApiKey) take the resource id as the mutation variable rather than an options object.
Hooks scoped to a community (useMessages, usePostMessage, …) take tokenAddress as the first positional argument.
mutation (PostMessageRequest) — auto-invalidates replies list
Community Members
Hook
Wraps
Kind
useCommunityMembers(tokenAddress, params?, opts?)
api.getCommunityMembers()
query
useWsTicket(tokenAddress, opts?)
api.getWsTicket()
mutation
Realtime
useCommunityEvents is not a query hook — it manages a WebSocket subscription via
CommunityRealtimeClient. See the SDK Reference — Realtime section.
import { useCommunityEvents } from '@coin-communities/sdk/react-query';import { api } from '@coin-communities/sdk';useCommunityEvents(tokenAddress, { auth: async () => { const { data } = await api.getWsTicket({ path: { token_address: tokenAddress } }); return data?.ticket ?? null; }, onMessage: (event) => { /* new message */ }, onLike: (event) => { /* like update */ },});
Business — API Key Origins
Hook
Wraps
Kind
useApiKeyOrigins(apiKeyId, opts?)
api.listApiKeyOrigins()
query
useAddApiKeyOrigin(opts?)
api.addApiKeyOrigin()
mutation (AddApiKeyOriginVariables) — auto-invalidates origins list
useRemoveApiKeyOrigin(opts?)
api.removeApiKeyOrigin()
mutation (RemoveApiKeyOriginVariables) — auto-invalidates origins list
queryKeys factory
queryKeys is a stable, typed object literal that exposes the cache key for every query the hooks use. Reach for it when you want to invalidate, prefetch, or read cache entries directly.