### Install SDK Source: https://coincommunities.org/docs/quickstart Install the Coin Communities SDK using your preferred package manager. ```bash bun add @coin-communities/sdk # npm add @coin-communities/sdk # yarn add @coin-communities/sdk ``` -------------------------------- ### Install SDK and React Query Source: https://coincommunities.org/docs/sdk/react-query Install the necessary packages for the Coin Communities SDK and React Query. ```bash bun add @coin-communities/sdk @tanstack/react-query ``` -------------------------------- ### Configure and Call HTTP API Source: https://coincommunities.org/docs/sdk/reference Demonstrates how to configure the API client and make a basic GET request. Handles potential errors by checking the error object. ```typescript import { configureApi, api } from '@coin-communities/sdk'; configureApi({ baseUrl: 'https://api.coin-communities.xyz', headers: { 'x-api-key': 'YOUR_KEY' }, }); const { data, error } = await api.getCommunity({ path: { token_address: '7eYw...' }, }); if (error) { console.error('failed', error.message); } else { console.log(data.community.tokenAddress); } ``` -------------------------------- ### Get SDK Information Source: https://coincommunities.org/docs/sdk/reference Retrieve metadata about the SDK, including its name, version, and the platform it's bundled for. The platform value depends on the runtime environment. ```javascript import { getSDKInfo } from '@coin-communities/sdk'; const info = getSDKInfo(); // { name: '@coin-communities/sdk', version: '0.0.8', platform: 'react' } ``` -------------------------------- ### End-to-End API Keys List and Create Flow Source: https://coincommunities.org/docs/sdk/react-query An example demonstrating a list-and-create flow for API keys. It invalidates the list cache after a successful mutation using `queryKeys.apiKeys.all`. ```typescript import { queryKeys, useApiKeys, useCreateApiKey, } from '@coin-communities/sdk/react-query'; import { useQueryClient } from '@tanstack/react-query'; export function ApiKeysList() { const qc = useQueryClient(); const keys = useApiKeys(); const create = useCreateApiKey({ onSuccess: () => qc.invalidateQueries({ queryKey: queryKeys.apiKeys.all }), }); if (keys.isLoading) return

Loading…

; if (keys.isError) return

Failed to load API keys.

; return ( <> ); } ``` -------------------------------- ### Low-Level Realtime Client Subscription Source: https://coincommunities.org/docs/examples/realtime This demonstrates how to use the `CommunityRealtimeClient` for low-level access to real-time events. It shows how to get a client instance, subscribe to events, and unsubscribe. ```typescript import { CommunityRealtimeClient } from '@coin-communities/sdk/react'; const client = CommunityRealtimeClient.getOrCreate({ baseUrl: 'https://api.coin-communities.xyz', tokenAddress: '7eYw...', auth: { getTicket: async () => { const { data } = await api.getWsTicket({ path: { token_address: '7eYw...' } }); if (!data?.ticket) throw new Error('WebSocket ticket unavailable'); return data.ticket; }, }, }); const dispose = client.subscribe({ onMessage: (e) => console.log(e), onModeration: (e) => console.log(e), onGap: () => console.log('reconnected — refetch'), onConnect: () => console.log('connected'), onDisconnect: () => console.log('disconnected'), }); // To stop receiving events from this handler: dispose(); ``` -------------------------------- ### Get like count Source: https://coincommunities.org/docs/examples/posting Retrieves the current like count for a specific message. ```APIDOC ## GET /getLikeCount ### Description Retrieves the current like count for a specific message. ### Method GET ### Endpoint `/getLikeCount` ### Parameters #### Path Parameters - **token_address** (string) - Required - The address of the token associated with the community. - **message_id** (string) - Required - The ID of the message to get the like count for. ### Response #### Success Response (200) - **data** (object) - Contains the like count. - **likeCount** (integer) - The number of likes for the message. ``` -------------------------------- ### Configure the SDK Source: https://coincommunities.org/docs/examples/quickstart Configure the SDK with the base URL and the created API key. ```javascript configureApi({ baseUrl: 'https://api.coin-communities.xyz', headers: { 'x-api-key': apiKey }, }); ``` -------------------------------- ### Import SDK Components Source: https://coincommunities.org/docs/sdk/reference Import necessary components from the main SDK package. Your bundler handles entry point resolution. ```javascript import { configureApi, getSDKInfo, SDK_NAME, SDK_VERSION, api } from '@coin-communities/sdk'; ``` -------------------------------- ### Get Authenticated Feed Source: https://coincommunities.org/docs/examples/feed Retrieves the authenticated user's feed. Requires an API key. ```javascript const { data } = await api.getFeed(); console.log(data?.items); // FeedItem[] ``` -------------------------------- ### Manage Message Likes Source: https://coincommunities.org/docs/examples/posting Includes functions to like, unlike, and get the like count for a message. These operations are synchronous. ```javascript await api.likeMessage({ path: { token_address: '7eYw...', message_id: 'msg_123' } }); await api.unlikeMessage({ path: { token_address: '7eYw...', message_id: 'msg_123' } }); const { data } = await api.getLikeCount({ path: { token_address: '7eYw...', message_id: 'msg_123' } }); ``` -------------------------------- ### getSDKInfo() Source: https://coincommunities.org/docs/sdk/reference Returns metadata describing the SDK and the runtime it was bundled for. ```APIDOC ## getSDKInfo() ### Description Returns metadata describing the SDK and the runtime it was bundled for. ### Signature ```typescript function getSDKInfo(): SDKInfo ``` ### Returns `SDKInfo` - An object containing the SDK's name, version, and platform. ### Platform-divergent behaviour The `platform` field reflects the conditional export resolved at bundle time. Runtime| `platform` value ---|--- Browser (React)| `'react'` React Native| `'react-native'` Node.js / default| `'node'` ### Request Example ```typescript import { getSDKInfo } from '@coin-communities/sdk'; const info = getSDKInfo(); // { name: '@coin-communities/sdk', version: '0.0.8', platform: 'react' } ``` ``` -------------------------------- ### Get Twitter OAuth URL Source: https://coincommunities.org/docs/quickstart Initiate the Twitter OAuth flow by obtaining the authorization URL. Specify your application's redirect URL. ```typescript // 1. Get the OAuth URL const { data: authData } = await api.twitterAuthUrl({ query: { redirectUrl: 'https://your-app.com/callback' }, }); // → redirect the user to authData.authUrl ``` -------------------------------- ### Get Community Details Source: https://coincommunities.org/docs/quickstart Retrieve details for a specific community using its token address. Handles potential errors by checking the `error` property. ```typescript import { api } from '@coin-communities/sdk'; // Read a community (requires API key) const { data, error } = await api.getCommunity({ path: { token_address: '7eYw...mintAddr' }, }); if (error) { console.error('failed', error.message); } else { console.log(data.community.tokenAddress); } ``` -------------------------------- ### Configure API and QueryClientProvider Source: https://coincommunities.org/docs/sdk/react-query Set up the SDK's API configuration and wrap your application with React Query's QueryClientProvider. Ensure the API base URL and authentication function are correctly configured. ```typescript 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 {children}; } ``` -------------------------------- ### Get Public Feed Source: https://coincommunities.org/docs/examples/feed Retrieves the public feed without requiring a signed-in user. Your API key is still sent via `configureApi`. ```javascript const { data } = await api.getFeedPublic(); ``` -------------------------------- ### Register a Business Account and Log In Source: https://coincommunities.org/docs/examples/quickstart Register a business account and log in to obtain a JWT. This is the first step for API access. ```javascript await api.register({ body: { businessName: 'My App', email: 'you@example.com', password: '...' } }); // confirm verification email const { data } = await api.login({ body: { email: 'you@example.com', password: '...' } }); ``` -------------------------------- ### configureApi() Source: https://coincommunities.org/docs/sdk/reference Configures the shared HTTP client for all api.* functions. This should be called once at application startup. ```APIDOC ## configureApi() ### Description Configures the shared HTTP client used by all `api.*` functions. Call this once at application startup — typically before any API call is made. ### Signature ```typescript function configureApi(options: ConfigureApiOptions): void ``` ### Parameters * **`options`** (`ConfigureApiOptions`, required) — Options accepted by `configureApi()`. ### Request Example ```typescript import { configureApi } from '@coin-communities/sdk'; configureApi({ baseUrl: 'https://api.coin-communities.xyz', headers: { 'x-api-key': 'YOUR_API_KEY' }, }); ``` ### Notes `baseUrl` is the API **origin**. The generated client paths already include `/api/v1/...`, so don't append it. ``` -------------------------------- ### Configure API Client with API Key Source: https://coincommunities.org/docs/quickstart Configure the SDK client with your API key for making authenticated requests. Set the `baseUrl` and `x-api-key` header. ```typescript import { configureApi } from '@coin-communities/sdk'; configureApi({ baseUrl: 'https://api.coin-communities.xyz', headers: { 'x-api-key': apiKey }, }); ``` -------------------------------- ### Configure API Base URL and Headers Source: https://coincommunities.org/docs/sdk/reference Configure the SDK with the base URL for API requests and custom headers, such as an API key. This should be called once at application startup. ```javascript import { configureApi } from '@coin-communities/sdk'; configureApi({ baseUrl: 'https://api.coin-communities.xyz', headers: { 'x-api-key': 'YOUR_API_KEY' }, }); ``` -------------------------------- ### HTTP API Configuration and Call Pattern Source: https://coincommunities.org/docs/sdk/reference How to configure the HTTP client and the general pattern for calling API operations. ```APIDOC ## HTTP API (`api.*`) All generated API operations are exported as a namespace called `api`. Configure the client once with `configureApi()`, then call operations directly. ### Call pattern By default operations return `{ data, error, response }`. Pass `{ throwOnError: true }` to throw on HTTP errors instead. ```typescript import { configureApi, api } from '@coin-communities/sdk'; configureApi({ baseUrl: 'https://api.coin-communities.xyz', headers: { 'x-api-key': 'YOUR_KEY' }, }); const { data, error } = await api.getCommunity({ path: { token_address: '7eYw...' }, }); if (error) { console.error('failed', error.message); } else { console.log(data.community.tokenAddress); } ``` Copy Operations that take a request body, path params, or query params accept them under the matching keys: ```typescript // Path params await api.getCommunity({ path: { token_address: '7eYw...' } }); // Query params await api.getMessages({ path: { token_address: '7eYw...' }, query: { limit: 50 } }); // Body await api.postMessage({ path: { token_address: '7eYw...' }, body: { content: 'gm', chainId: 'solana', walletAddress: 'YourWalletPubkey' }, }); ``` Copy ### Type names The generated types follow each operation's name. For an operation `xxx()` you get: * `XxxData` — request shape (body / path / query / url) * `XxxResponses` — map of status code → response body * `XxxResponse` — union of success response bodies * `XxxErrors` — map of status code → error body * `XxxError` — union of error bodies (where applicable) Refer to `types.gen.ts` and `openapi.json` in the SDK package for the full schema. ``` -------------------------------- ### Create and Subscribe to Community Realtime Client Source: https://coincommunities.org/docs/sdk/reference Instantiate a shared WebSocket client for a given base URL and token address. The client handles reconnections automatically. Subscribe to various events like messages, moderation updates, likes, connection status, and gaps in data. ```javascript const client = CommunityRealtimeClient.getOrCreate({ baseUrl: 'https://api.coin-communities.xyz', tokenAddress: '7eYw...', auth: { // Fetches a fresh single-use ticket on connect and every reconnect. getTicket: async () => { const { data } = await api.getWsTicket({ path: { token_address: '7eYw...' } }); if (!data?.ticket) throw new Error('WebSocket ticket unavailable'); return data.ticket; }, }, }); const dispose = client.subscribe({ onMessage: (event) => console.log('message persisted', event), onModeration: (event) => console.log('moderation update', event), onLike: (event) => console.log('like update', event), onGap: () => console.log('reconnected — refetch via REST'), onConnect: () => console.log('connected'), onDisconnect: () => console.log('disconnected'), }); // Later: dispose(); // unsubscribe this handler (connection shared with other subscribers) ``` -------------------------------- ### Configure API with Server Keys Source: https://coincommunities.org/docs/sdk/reference Configure the SDK for server-side operations using server API key pairs. Ensure these keys are kept secure and never exposed to the browser. ```javascript configureApi({ baseUrl: 'https://api.coin-communities.xyz', headers: { 'x-server-key': process.env.CC_SERVER_KEY, 'x-server-secret': process.env.CC_SERVER_SECRET, }, }); ``` -------------------------------- ### walletChallenge Source: https://coincommunities.org/docs/sdk/reference Requests a challenge to sign for wallet linking. ```APIDOC ## walletChallenge ### Description Requests a challenge to sign for wallet linking. The returned message must be signed and passed to `linkWallet`. ### Request Body - **address** (string) - Required - **chainType** (ChainType) - Required ### Response #### Success Response - **message** (string) - The message to be signed. - **nonce** (string) - A nonce associated with the challenge. ``` -------------------------------- ### Create API Key Source: https://coincommunities.org/docs/examples/api-keys Creates a new API key for the business account. The full key is returned only during creation and must be stored immediately. ```APIDOC ## Create a key ### Description Creates a new API key associated with the business account. The full secret key is only provided at the time of creation and cannot be retrieved later. ### Method POST (assumed based on creation action) ### Endpoint `/api/v1/api-keys` (assumed based on common REST patterns) ### Parameters #### Request Body - **name** (string) - Required - A name for the API key (e.g., 'production'). ### Request Example ```json { "name": "production" } ``` ### Response #### Success Response (201 Created - assumed) - **key** (string) - The full secret API key. This is only shown once. - **apiKey** (object) - An object containing details about the created key. - **keyPrefix** (string) - A safe-to-display prefix of the API key. ``` -------------------------------- ### Create an API Key Source: https://coincommunities.org/docs/examples/quickstart Use the JWT obtained from login to create an API key for day-to-day requests. Store the key immediately as it's shown only once. ```javascript configureApi({baseUrl: 'https://api.coin-communities.xyz', auth: jwt}); const { data } = await api.createApiKey({ body: { name: 'production' } }); // data.key is shown only once — store it immediately ``` -------------------------------- ### Platform Type Source: https://coincommunities.org/docs/sdk/reference Defines the possible platform values for the SDK, indicating the environment it's bundled for. ```typescript type Platform = 'react' | 'react-native' | 'node'; ``` -------------------------------- ### Use usePing Query Hook Source: https://coincommunities.org/docs/sdk/react-query Check the API's responsiveness using the usePing hook. This is a read operation. ```typescript const { data, isLoading, error } = usePing(); ``` -------------------------------- ### SDK Version Constant Source: https://coincommunities.org/docs/sdk/reference The current version string of the SDK. ```typescript const SDK_VERSION: string ``` -------------------------------- ### SDK Name Constant Source: https://coincommunities.org/docs/sdk/reference The package name string for the SDK. ```typescript const SDK_NAME: string ``` -------------------------------- ### Create API Key Source: https://coincommunities.org/docs/quickstart Create an API key for your business account using the JWT obtained from login. Store the key securely as it's only shown once. ```typescript import { configureApi, api } from '@coin-communities/sdk'; // Use the JWT to authenticate the key-creation call configureApi({ baseUrl: 'https://api.coin-communities.xyz', auth: jwt, }); const { data: keyData } = await api.createApiKey({ body: { name: 'production' }, }); // Store this immediately — the full key is shown only once const apiKey = keyData?.key; ``` -------------------------------- ### Link Wallet and Post a Message Source: https://coincommunities.org/docs/examples/quickstart Link a Solana wallet to the user's account by signing a challenge, then post a message to a community. ```javascript // Link a Solana wallet const { data: challenge } = await api.walletChallenge({ body: { address: 'YourWalletPubkey', chainType: 'svm' }, }); // sign challenge.message with the wallet, then: await api.linkWallet({ body: { address: 'YourWalletPubkey', chainType: 'svm', signature: walletSig }, }); // Post await api.postMessage({ path: { token_address: '7eYw...mintAddr' }, body: { content: 'gm', chainId: 'solana', walletAddress: 'YourWalletPubkey' }, }); ``` -------------------------------- ### HTTP API Request Parameters Source: https://coincommunities.org/docs/sdk/reference Illustrates how to pass different types of parameters (path, query, body) to API operations. ```typescript // Path params await api.getCommunity({ path: { token_address: '7eYw...' } }); // Query params await api.getMessages({ path: { token_address: '7eYw...' }, query: { limit: 50 } }); // Body await api.postMessage({ path: { token_address: '7eYw...' }, body: { content: 'gm', chainId: 'solana', walletAddress: 'YourWalletPubkey' }, }); ``` -------------------------------- ### Use useMediaProviders Query Hook Source: https://coincommunities.org/docs/sdk/react-query Fetch available media providers for a community using the useMediaProviders query hook. This is a read operation. ```typescript const { data, isLoading, error } = useMediaProviders(); ``` -------------------------------- ### Handling Dropped Connections with onGap Source: https://coincommunities.org/docs/examples/realtime Demonstrates how to use the `onGap` callback within `useCommunityEvents` to trigger a REST refetch after a connection drop. This ensures no moderation outcomes are missed. ```typescript const queryClient = useQueryClient(); useCommunityEvents(tokenAddress, { auth, onGap: () => { void queryClient.invalidateQueries({ queryKey: ['community', tokenAddress, 'messages'], }); }, }); ``` -------------------------------- ### Configure API with JWT Authentication Source: https://coincommunities.org/docs/sdk/reference Configure the SDK to use JWT for authentication by providing a function that returns the token. This is suitable for business management operations. ```javascript configureApi({ baseUrl: 'https://api.coin-communities.xyz', auth: () => sessionStorage.getItem('token') ?? '', }); ``` -------------------------------- ### Use useMe Query Hook Source: https://coincommunities.org/docs/sdk/react-query Fetch the current authenticated user's information using the useMe hook. This is a read operation. ```typescript const { data, isLoading, error } = useMe(); ``` -------------------------------- ### Register Business Account Source: https://coincommunities.org/docs/quickstart Register a new business account to obtain credentials for API access. Ensure you confirm the verification email. ```typescript import { api } from '@coin-communities/sdk'; await api.register({ body: { businessName: 'My App', email: 'you@example.com', password: 'a-strong-password', }, }); // → confirm the verification email, then login: const { data } = await api.login({ body: { email: 'you@example.com', password: 'a-strong-password' }, }); const jwt = data?.token; ``` -------------------------------- ### Create an API Key Source: https://coincommunities.org/docs/examples/api-keys Use this snippet to create a new API key. The full secret key is returned only upon creation and must be stored immediately. ```javascript const { data } = await api.createApiKey({ body: { name: 'production' } }); const { key, apiKey } = data; // key — the full secret (shown once only) // apiKey.keyPrefix — safe to display in UIs ``` -------------------------------- ### SDK Constants Source: https://coincommunities.org/docs/sdk/reference Constants available in the SDK for package name and version. ```APIDOC ## SDK Constants ### `SDK_NAME` ``` const SDK_NAME: string ``` Copy The package name string. Value: `'@coin-communities/sdk'`. ### `SDK_VERSION` ``` const SDK_VERSION: string ``` Copy The current SDK version string. ``` -------------------------------- ### Use useCallbacks Query Hook Source: https://coincommunities.org/docs/sdk/react-query Fetch a list of configured callbacks using the useCallbacks query hook. This is a read operation. ```typescript const { data, isLoading, error } = useCallbacks(); ``` -------------------------------- ### Use useServerApiKeys Query Hook Source: https://coincommunities.org/docs/sdk/react-query Retrieve a list of server API keys using the useServerApiKeys query hook. This is a read operation. ```typescript const { data, isLoading, error } = useServerApiKeys(); ``` -------------------------------- ### Use useCreateServerApiKey Mutation Hook Source: https://coincommunities.org/docs/sdk/react-query Create a new server API key using the useCreateServerApiKey mutation hook. It accepts a CreateServerApiKeyRequest object. ```typescript const { mutate, isLoading, error } = useCreateServerApiKey(); // To trigger the mutation: // mutate({ name: 'My Server Key', permissions: ['admin'] }); ``` -------------------------------- ### Wallet Hooks Source: https://coincommunities.org/docs/sdk/react-query Hooks for managing user wallets and authentication. ```APIDOC ## useWallets ### Description Fetches a list of the user's linked wallets. ### Method query ### Endpoint api.getWallets() ## useWalletChallenge ### Description Initiates a challenge for wallet authentication. ### Method mutation ### Endpoint api.walletChallenge(WalletChallengeRequest) ## useLinkWallet ### Description Links a new wallet to the user's account. ### Method mutation ### Endpoint api.linkWallet(LinkWalletRequest) ## useUnlinkWallet ### Description Unlinks a wallet from the user's account. ### Method mutation ### Endpoint api.unlinkWallet(id: string) ``` -------------------------------- ### SDK Info Type Source: https://coincommunities.org/docs/sdk/reference Defines the structure of the object returned by `getSDKInfo()`, containing the SDK's name, version, and platform. ```typescript interface SDKInfo { name: string; version: string; platform: Platform; } ``` -------------------------------- ### bindCommunityEventsToQueryClient Source: https://coincommunities.org/docs/sdk/reference Integrates a `CommunityRealtimeClient` with a TanStack Query `QueryClient`. It automatically updates the cache with real-time events, enabling live data synchronization without requiring React components. ```APIDOC ## `bindCommunityEventsToQueryClient` Wires a `CommunityRealtimeClient` into a TanStack Query `QueryClient`, automatically invalidating and patching cache entries as realtime events arrive. Useful in scenarios where you want live cache updates without mounting a React component. ### Signature ```typescript function bindCommunityEventsToQueryClient( queryClient: QueryClient, tokenAddress: string, options?: { baseUrl?: string; auth?: RealtimeAuth }, ): () => void; ``` Returns an unsubscribe function. ### Example ```javascript import { bindCommunityEventsToQueryClient } from '@coin-communities/sdk'; import { QueryClient } from '@tanstack/react-query'; const qc = new QueryClient(); const unsubscribe = bindCommunityEventsToQueryClient(qc, '7eYw...', { baseUrl: 'https://api.coin-communities.xyz', auth: { getTicket: async () => (await api.getWsTicket({ path: { token_address: '7eYw...' } })).data?.ticket ?? '' }, }); // Later: unsubscribe(); ``` ``` -------------------------------- ### Import CommunityRealtimeClient for Browser/React Native Source: https://coincommunities.org/docs/sdk/reference Import the CommunityRealtimeClient for use in browser or React Native environments. The SDK resolves this automatically when bundled. ```javascript // Resolved automatically when bundled for browser or React Native import { CommunityRealtimeClient } from '@coin-communities/sdk'; ``` ```javascript // or explicit subpath import { CommunityRealtimeClient } from '@coin-communities/sdk/react'; ``` ```javascript import { CommunityRealtimeClient } from '@coin-communities/sdk/react-native'; ``` -------------------------------- ### Attach Media to a Post Source: https://coincommunities.org/docs/examples/posting Uploads media first using `uploadCommunityMedia` and then includes the returned media URL in the `postMessage` call. Only URLs from `uploadCommunityMedia` or listed providers are accepted. ```javascript const { data: media } = await api.uploadCommunityMedia({ body: { contentType: 'image/jpeg', data: btoa(rawImageBytes), // base64 }, }); await api.postMessage({ path: { token_address: '7eYw...' }, body: { content: 'Check this chart', chainId: 'solana', walletAddress: 'YourWallet', mediaUrl: media.mediaUrl, }, }); ``` -------------------------------- ### List callbacks Source: https://coincommunities.org/docs/examples/callbacks Retrieves a list of all registered callback URLs for the authenticated user. ```APIDOC ## List callbacks ### Description Retrieves a list of all registered callback URLs. ### Method GET (inferred from `listCallbacks`) ### Endpoint `/callbacks` (inferred from context) ### Response #### Success Response (200) - **data** (array) - A list of registered callback objects. ``` -------------------------------- ### Configure API Options Type Source: https://coincommunities.org/docs/sdk/reference Defines the structure for options accepted by the `configureApi` function, including base URL, fetch implementation, headers, and authentication. ```typescript type ConfigureApiOptions = Pick; ``` -------------------------------- ### Configure API Client with JWT Auth Source: https://coincommunities.org/docs/quickstart Configure the SDK client to use a bearer JWT for authentication, typically for business management operations. This uses a callback to retrieve the token. ```typescript configureApi({ baseUrl: 'https://api.coin-communities.xyz', headers: { 'x-api-key': apiKey }, auth: () => sessionStorage.getItem('business_jwt') ?? '', }); ``` -------------------------------- ### Server API Keys Hooks Source: https://coincommunities.org/docs/sdk/react-query Hooks for managing server-side API keys. ```APIDOC ## useServerApiKeys ### Description Retrieves a list of server API keys. ### Method query ### Parameters #### Query Parameters - **opts** (object) - Optional - React Query options. ## useCreateServerApiKey ### Description Creates a new server API key. ### Method mutation ### Parameters #### Request Body - **CreateServerApiKeyRequest** (object) - Required - Details for creating a server API key. ## useRevokeServerApiKey ### Description Revokes an existing server API key. ### Method mutation ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the server API key to revoke. ``` -------------------------------- ### Handle Asynchronous Post Processing Source: https://coincommunities.org/docs/examples/posting Demonstrates that `postMessage` returns an empty response upon acceptance for processing. The actual persistence and availability of the message happen later. ```javascript const { data } = await api.postMessage({ path, body }); // data is undefined — the 200 only means "accepted for processing" ``` -------------------------------- ### CommunityRealtimeClient Source: https://coincommunities.org/docs/sdk/reference Provides a shared WebSocket client for real-time community events. It handles connection management, including automatic reconnection with exponential back-off. You can subscribe to various events like messages, moderation updates, and likes. ```APIDOC ## `CommunityRealtimeClient` A shared WebSocket client per `(baseUrl, tokenAddress)` pair. Call `getOrCreate` to get or lazily spin up a connection; `CommunityRealtimeClient` handles reconnection with exponential back-off automatically. ### Usage ```javascript const client = CommunityRealtimeClient.getOrCreate({ baseUrl: 'https://api.coin-communities.xyz', tokenAddress: '7eYw...', auth: { // Fetches a fresh single-use ticket on connect and every reconnect. getTicket: async () => { const { data } = await api.getWsTicket({ path: { token_address: '7eYw...' } }); if (!data?.ticket) throw new Error('WebSocket ticket unavailable'); return data.ticket; }, }, }); const dispose = client.subscribe({ onMessage: (event) => console.log('message persisted', event), onModeration: (event) => console.log('moderation update', event), onLike: (event) => console.log('like update', event), onGap: () => console.log('reconnected — refetch via REST'), onConnect: () => console.log('connected'), onDisconnect: () => console.log('disconnected'), }); // Later: dispose(); // unsubscribe this handler (connection shared with other subscribers) ``` ``` -------------------------------- ### Register a Callback URL Source: https://coincommunities.org/docs/examples/callbacks Use this snippet to register a URL that will receive HTTP POST notifications for community events. Ensure you have a valid business JWT for authentication. ```javascript const { data } = await api.addCallback({ body: { url: 'https://your-server.com/cc-webhook' }, }); ``` -------------------------------- ### Use useLogs Query Hook Source: https://coincommunities.org/docs/sdk/react-query Fetch logs using the useLogs query hook. This is a read operation and accepts optional parameters and React Query options. ```typescript const { data, isLoading, error } = useLogs({ limit: 10, offset: 0 }, { enabled: true }); ``` -------------------------------- ### Community Media Hooks Source: https://coincommunities.org/docs/sdk/react-query Hooks for uploading and managing community media. ```APIDOC ## useUploadCommunityMedia ### Description Uploads media to a community. ### Method mutation ### Parameters #### Request Body - **UploadMediaRequest** (object) - Required - The media to upload. ## useMediaProviders ### Description Retrieves available media providers. ### Method query ### Parameters #### Query Parameters - **opts** (object) - Optional - React Query options. ``` -------------------------------- ### Use useLogin Mutation Hook Source: https://coincommunities.org/docs/sdk/react-query Log in a user with provided credentials using the useLogin mutation hook. It accepts a LoginRequest object. ```typescript const { mutate, isLoading, error } = useLogin(); // To trigger the mutation: // mutate({ username: 'user', password: 'password' }); ``` -------------------------------- ### Use useRegister Mutation Hook Source: https://coincommunities.org/docs/sdk/react-query Register a new user with the provided registration details using the useRegister mutation hook. It accepts a RegisterRequest object. ```typescript const { mutate, isLoading, error } = useRegister(); // To trigger the mutation: // mutate({ username: 'newUser', email: 'new@example.com', password: 'password123' }); ``` -------------------------------- ### Chains & Feed Hooks Source: https://coincommunities.org/docs/sdk/react-query Hooks for fetching supported chains and community feeds. ```APIDOC ## useSupportedChains ### Description Fetches a list of supported blockchain chains. ### Method query ### Endpoint api.getSupportedChains() ## useTopCommunities ### Description Fetches a list of top communities. ### Method query ### Endpoint api.getTopCommunities() ## useFeed ### Description Fetches the user's community feed. ### Method query ### Endpoint api.getFeed() ## useFeedPublic ### Description Fetches a public community feed. ### Method query ### Endpoint api.getFeedPublic() ``` -------------------------------- ### API Keys Hooks Source: https://coincommunities.org/docs/sdk/react-query Hooks for managing API keys, including creation, rotation, and revocation. ```APIDOC ## useApiKeys ### Description Retrieves a list of API keys. ### Method query ### Parameters #### Query Parameters - **opts** (object) - Optional - React Query options. ## useCreateApiKey ### Description Creates a new API key. ### Method mutation ### Parameters #### Request Body - **CreateApiKeyRequest** (object) - Required - Details for creating an API key. ## useRotateApiKey ### Description Rotates an existing API key. ### Method mutation ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the API key to rotate. ## useRevokeApiKey ### Description Revokes an existing API key. ### Method mutation ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the API key to revoke. ``` -------------------------------- ### Sign in a User via Twitter Source: https://coincommunities.org/docs/examples/quickstart Initiate Twitter OAuth for end-user authentication and exchange the challenge code for a session. ```javascript // Get the OAuth redirect URL const { data } = await api.twitterAuthUrl({ query: { redirectUrl: 'https://your-app.com/callback' } }); // Redirect user to data.authUrl // On callback, exchange the code: const { data: session } = await api.twitterChallengeExchange({ body: { challengeCode: params.get('challengeCode') }, }); // session.accessToken is the user's bearer token ``` -------------------------------- ### Post a Message Source: https://coincommunities.org/docs/examples/posting Posts a message to a community. Requires authentication, a linked wallet, and the correct wallet address. The post is accepted for processing asynchronously. ```javascript await api.postMessage({ path: { token_address: '7eYw...mintAddr' }, body: { content: 'This is my take on $TOKEN', chainId: 'solana', walletAddress: 'YourLinkedSolanaWallet', }, throwOnError: true, }); ``` -------------------------------- ### uploadMedia / uploadPfp Source: https://coincommunities.org/docs/sdk/reference Uploads media or a profile picture. ```APIDOC ## uploadMedia / uploadPfp ### Description Uploads media content or a profile picture. Both operations share the same request structure. ### Request Body - **contentType** (string) - Required - e.g. 'image/jpeg' - **data** (string) - Required - base64-encoded file content ### Response (uploadCommunityMedia) #### Success Response - **mediaUrl** (string) ### Response (uploadPfp) #### Success Response - **imageUrl** (string) ``` -------------------------------- ### Wallet Management Source: https://coincommunities.org/docs/sdk/reference Operations for linking and unlinking EVM and Solana wallets to a user account. ```APIDOC ## GET /api/v1/users/me/wallets ### Description List linked wallets. ### Method GET ### Endpoint /api/v1/users/me/wallets ### Auth api key ## POST /api/v1/users/me/wallets/challenge ### Description Request a sign-in challenge for the wallet. ### Method POST ### Endpoint /api/v1/users/me/wallets/challenge ### Auth api key ## POST /api/v1/users/me/wallets ### Description Link a wallet using the signed challenge nonce. ### Method POST ### Endpoint /api/v1/users/me/wallets ### Parameters #### Request Body - **nonce** (string) - Required - The signed challenge nonce. - **signature** (string) - Required - The signature of the nonce. - **walletAddress** (string) - Required - The wallet address to link. ### Auth api key ## DELETE /api/v1/users/me/wallets/{id} ### Description Unlink a wallet. ### Method DELETE ### Endpoint /api/v1/users/me/wallets/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the wallet to unlink. ### Auth api key ``` -------------------------------- ### Register a callback Source: https://coincommunities.org/docs/examples/callbacks Registers a URL to receive HTTP POST notifications when community events occur. This operation requires a business JWT for authentication. ```APIDOC ## Register a callback ### Description Registers a URL to receive HTTP POST notifications for community events. ### Method POST (inferred from `addCallback`) ### Endpoint `/callbacks` (inferred from context) ### Parameters #### Request Body - **url** (string) - Required - The URL to register for receiving webhook notifications. ### Request Example ```json { "url": "https://your-server.com/cc-webhook" } ``` ### Response #### Success Response (200) - **data** (object) - Contains information about the registered callback. ``` -------------------------------- ### Logs Hooks Source: https://coincommunities.org/docs/sdk/react-query Hooks for retrieving activity logs. ```APIDOC ## useLogs ### Description Retrieves activity logs. ### Method query ### Parameters #### Query Parameters - **params** (object) - Optional - Parameters for filtering logs. - **opts** (object) - Optional - React Query options. ``` -------------------------------- ### Business Callbacks Source: https://coincommunities.org/docs/sdk/reference Manage webhook callbacks for community events. Register, list, and remove callback URLs. ```APIDOC ## listCallbacks ### Description List registered callback URLs. ### Method GET ### Endpoint /api/v1/business/callbacks ### Auth jwt ## addCallback ### Description Register a callback URL. ### Method POST ### Endpoint /api/v1/business/callbacks ### Auth jwt ## removeCallback ### Description Remove a callback URL. ### Method DELETE ### Endpoint /api/v1/business/callbacks/{id} ### Auth jwt ``` -------------------------------- ### Use useLikeCount Query Hook Source: https://coincommunities.org/docs/sdk/react-query Fetch the like count for a specific message within a community using the useLikeCount query hook. It requires the community's token address and the message ID. ```typescript const { data, isLoading, error } = useLikeCount('community_token_address', 'message_id'); ``` -------------------------------- ### realtimeAuthFromApiClient Source: https://coincommunities.org/docs/sdk/reference Constructs a `RealtimeGetTicketAuth` object by fetching a WebSocket ticket using an existing SDK REST client. This function automatically forwards any configured JWT or API key to the ticket endpoint. ```APIDOC ## `realtimeAuthFromApiClient` Builds a `RealtimeGetTicketAuth` by fetching a fresh WebSocket ticket via the SDK's generated REST client. The JWT (`Authorization`) and/or `x-api-key` already configured on the client are forwarded to the ticket endpoint automatically. ### Signature ```typescript function realtimeAuthFromApiClient( client: Client, tokenAddress: string, ): RealtimeGetTicketAuth; ``` ### Example ```javascript import { realtimeAuthFromApiClient, CommunityRealtimeClient } from '@coin-communities/sdk'; import { createClient } from '@hey-api/client-fetch'; const httpClient = createClient({ baseUrl: 'https://api.coin-communities.xyz' }); const auth = realtimeAuthFromApiClient(httpClient, '7eYw...'); const rtClient = CommunityRealtimeClient.getOrCreate({ baseUrl: 'https://api.coin-communities.xyz', tokenAddress: '7eYw...', auth, }); ``` ``` -------------------------------- ### linkWallet Source: https://coincommunities.org/docs/sdk/reference Links a wallet to the user's account. ```APIDOC ## linkWallet ### Description Links a wallet to the user's account using the provided details and signature. ### Request Body - **address** (string) - Required - wallet public address - **chainType** (ChainType) - Required - **signature** (string) - Required - signature over the nonce from walletChallenge ### Errors - **400** no pending challenge - **401** invalid signature - **409** wallet already linked ``` -------------------------------- ### User Hooks Source: https://coincommunities.org/docs/sdk/react-query Hooks for managing user profiles and authentication. ```APIDOC ## useUser ### Description Fetches the current authenticated user's profile. ### Method query ### Endpoint api.userMe() ## useUpdateUsername ### Description Updates the username of the authenticated user. ### Method mutation ### Endpoint api.updateUsername(UpdateUsernameRequest) ## useUploadPfp ### Description Uploads a profile picture for the authenticated user. ### Method mutation ### Endpoint api.uploadPfp(UploadPfpRequest) ``` -------------------------------- ### List API Key Origins Source: https://coincommunities.org/docs/examples/api-keys Lists all origins that are allowed to use a specific API key. ```APIDOC ## List origins ### Description Lists all origins that have been configured to use a specific API key. ### Method GET (assumed based on listing action) ### Endpoint `/api/v1/api-keys/{id}/origins` (assumed based on common REST patterns) ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the API key whose origins are to be listed. ``` -------------------------------- ### getLogs Source: https://coincommunities.org/docs/sdk/reference Retrieves logs with filtering options. ```APIDOC ## getLogs ### Description Retrieves logs with filtering options based on provided parameters. ### Query Parameters #### Query Parameters - **apiKeyId** (string | null) - Optional - filter to a specific API key - **method** (string | null) - Optional - HTTP method e.g. 'GET' - **path** (string | null) - Optional - request path prefix - **statusClass** (number | null) - Optional - 2 = 2xx, 4 = 4xx, 5 = 5xx - **startTime** (string | null) - Optional - ISO-8601 lower bound - **endTime** (string | null) - Optional - ISO-8601 upper bound - **limit** (number) - Optional - **offset** (number) - Optional - default 0 ``` -------------------------------- ### Authentication Hooks Source: https://coincommunities.org/docs/sdk/react-query Hooks for managing user authentication, including login, logout, registration, and password management. ```APIDOC ## useMe ### Description Retrieves the currently authenticated user's information. ### Method query ### Parameters #### Query Parameters - **opts** (object) - Optional - React Query options. ## useLogin ### Description Logs in a user with provided credentials. ### Method mutation ### Parameters #### Request Body - **LoginRequest** (object) - Required - User login credentials. ## useLogout ### Description Logs out the currently authenticated user. ### Method mutation ### Parameters #### Request Body - **void** - No request body required. ## useRegister ### Description Registers a new user. ### Method mutation ### Parameters #### Request Body - **RegisterRequest** (object) - Required - User registration details. ## useVerifyEmail ### Description Verifies a user's email address. ### Method mutation ### Parameters #### Request Body - **VerifyEmailRequest** (object) - Required - Email verification details. ## useResendVerification ### Description Resends the email verification code. ### Method mutation ### Parameters #### Request Body - **ResendVerificationRequest** (object) - Required - Resend verification details. ## useForgotPassword ### Description Initiates the password reset process. ### Method mutation ### Parameters #### Request Body - **ForgotPasswordRequest** (object) - Required - Forgot password details. ## useResetPassword ### Description Resets a user's password. ### Method mutation ### Parameters #### Request Body - **ResetPasswordRequest** (object) - Required - Reset password details. ## useRefreshToken ### Description Refreshes the user's authentication token. ### Method mutation ### Parameters #### Request Body - **RefreshTokenRequest** (object) - Required - Refresh token details. ``` -------------------------------- ### Callbacks Hooks Source: https://coincommunities.org/docs/sdk/react-query Hooks for managing webhook callbacks. ```APIDOC ## useCallbacks ### Description Retrieves a list of configured callbacks. ### Method query ### Parameters #### Query Parameters - **opts** (object) - Optional - React Query options. ## useAddCallback ### Description Adds a new callback URL. ### Method mutation ### Parameters #### Request Body - **AddCallbackRequest** (object) - Required - Details for adding a callback. ## useRemoveCallback ### Description Removes a callback URL. ### Method mutation ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the callback to remove. ``` -------------------------------- ### Post a Message to a Community Source: https://coincommunities.org/docs/quickstart Post a message to a community. Requires the community's token address, content, chain ID, and the user's wallet address. Errors will be thrown directly. ```typescript await api.postMessage({ path: { token_address: '7eYw...mintAddr' }, body: { content: 'gm', chainId: 'solana', // 'solana' | 'ethereum' | 'base' | 'bsc' walletAddress: 'YourWalletPublicKey', }, throwOnError: true, }); ``` -------------------------------- ### Use useCommunity Query Hook Source: https://coincommunities.org/docs/sdk/react-query Fetch details for a specific community using the useCommunity query hook. It requires the community's token address. ```typescript const { data, isLoading, error } = useCommunity('community_token_address'); ``` -------------------------------- ### getFeed Source: https://coincommunities.org/docs/examples/feed Retrieves an authenticated feed of activity across all communities. Requires an API key. ```APIDOC ## getFeed ### Description Retrieves an aggregated feed of activity across all communities for an authenticated user. ### Method GET ### Endpoint /feed ### Parameters #### Query Parameters None #### Request Body None ### Request Example ```javascript const { data } = await api.getFeed(); console.log(data?.items); // FeedItem[] ``` ### Response #### Success Response (200) - **items** (FeedItem[]) - An array of feed items. ### FeedItem fields Field| Description ---|--- `tokenAddress`| Community the message came from `tokenSymbol`| Token ticker (e.g. `FWOG`) `tokenImageUrl`| Token logo `content`| Message text `username`| Author's display name `likeCount`| Current like count `replyCount`| Number of replies `createdAt`| ISO-8601 timestamp ``` -------------------------------- ### postMessageServer / postReplyServer Source: https://coincommunities.org/docs/sdk/reference Posts a message or a reply to a message on the server. ```APIDOC ## postMessageServer / postReplyServer ### Description Posts a message or a reply to a message on the server, attributing it to a specific user. ### Request Body - **content** (string) - Required - **chainId** (ChainId) - Required - **walletAddress** (string) - Required - must be a linked wallet - **twitterId** (string) - Required - user to attribute the post to - **invalidateCache** (boolean | null) - Optional - drop cached balance-eligibility before posting ### Attributes - **`twitterId`**— the Twitter ID of the user the message is posted on behalf of. - **`invalidateCache`**— when`true` , drops the server's cached balance-eligibility entry for this wallet before checking, forcing a fresh RPC/price lookup. ```