Quickstart
Get from install to first API call in a few minutes.
Install
pnpm add @coin-communities/sdk
# npm add @coin-communities/sdk
# yarn add @coin-communities/sdkPeer dependencies (react, react-native, @tanstack/react-query) are all optional —
install only the ones your project uses.
Get an API key
Most operations require an API key sent as the x-api-key request header.
API keys are provisioned by the Coin Communities team — contact support to
request one for your integration. Keys are validated on every request; treat
them as secrets and keep them out of client bundles where possible.
Configure
Once you have an API key, configure the client once at startup:
import { configureApi } from '@coin-communities/sdk';
configureApi({
baseUrl: 'https://api.coin-communities.xyz',
headers: { 'x-api-key': apiKey },
});For per-user operations that require a bearer JWT (obtained via the Twitter
OAuth flow), set auth as well:
configureApi({
baseUrl: 'https://api.coin-communities.xyz',
headers: { 'x-api-key': apiKey },
auth: () => sessionStorage.getItem('user_jwt') ?? '',
});Make a request
All generated operations live under the api namespace. By default they return
{ data, error, response } — pass { throwOnError: true } to throw instead.
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);
}Post a message (the wallet must be linked to the authenticated user):
await api.postMessage({
path: { token_address: '7eYw...mintAddr' },
body: {
content: 'gm',
chainId: 'solana', // 'solana' | 'ethereum' | 'base' | 'bsc'
walletAddress: 'YourWalletPublicKey',
},
throwOnError: true,
});Browse the public feed (no signed-in user required — still needs your API key):
const { data } = await api.getFeedPublic();
console.log(data?.items);User sign-in (Twitter OAuth)
End-users authenticate via Twitter. The flow uses your API key throughout:
// 1. Get the OAuth URL
const { data: authData } = await api.twitterAuthUrl({
query: { redirectUrl: 'https://your-app.com/callback' },
});
// → redirect the user to authData.authUrl
// 2. After the redirect, exchange the challengeCode
const { data: session } = await api.twitterChallengeExchange({
body: { challengeCode: searchParams.get('challengeCode') },
});
const { accessToken, refreshToken, user } = session;Store accessToken and pass it via the auth option (or Authorization: Bearer header)
for subsequent user-scoped calls.
Next steps
- SDK Reference — every operation by domain, with request/response types.
- React Query — pre-baked hooks and
queryKeysfor React apps.