Node SDK
kredo is the server kit. No dependencies, Node 18 or later.
npm install kredoSetup
import { Credits } from "kredo";
const credits = new Credits({
apiKey: process.env.CREDITS_API_KEY!,
signerKey: process.env.CREDITS_SIGNER_KEY, // signs your live charges
});| Option | Default | Meaning |
|---|---|---|
apiKey | required | Your app's live (uc_live_) or test (uc_test_) key |
signerKey | none | Your app's NEAR key, ed25519:.... Live charges, holds, captures, refunds and conversions are signed with it. It never leaves your server: the SDK signs locally and sends only the signature. See who signs a charge |
baseUrl | https://kredo-near-api.onrender.com | The network's API |
pagesUrl | https://kredo-near.vercel.app | The hosted connect, buy and account pages |
retries | 2 | Extra tries after a network failure or rate limit. Writes are safe to retry: each carries a ref |
timeoutMs | 60000 | Per request. Long enough for a transaction to confirm |
Amounts are credits, as a number or an exact decimal string such as "0.5". Every amount the SDK returns is { credits, usd, units }.
Pricing
| Call | What it does |
|---|---|
prices() | Your price list |
setPrices(prices) | Replaces it. { price } per action, or { rate, unit } per unit |
setProfile(profile) | Your directory listing: { name?, description?, logoUrl?, website?, category? } |
quote({ action, quantity } | { credits }) | Price, network fee and what you earn |
Users
| Call | What it does |
|---|---|
connectUrl({ credits, returnTo, expiresInDays }) | Link to the connect page |
exchangeCode(code) | Swaps the one-time code for { user } |
user(account) | Balance, limit, whether they're connected, and what's spendable now |
session(user) | Everything the React kit renders, for a user or undefined |
buyUrl({ credits, returnTo }), accountUrl() | Links to the buy and account pages |
Moving credits
| Call | What it does |
|---|---|
charge({ user, action | credits, quantity, ref }) | Charges now |
hold({ user, action | credits, quantity, ref, ttlSeconds }) | Reserves credits, price locked |
capture(holdId, { credits }) | Charges all or part of a hold, returns the rest |
release(holdId) | Returns the whole hold |
refund({ user, credits, ref }) | Gives credits back, up to what they spent with you |
setExchangeRate(rate) | Light mode: our credits per one of yours, or null to turn it off |
convert({ user, credits, ref }) | Light mode: returns appCredits, how many of yours to add |
Every result includes txHash and an explorer link.
On a live key, charge, hold, capture, refund and convert make two requests. The API prepares the vault call as a transaction from your app's signer account. The SDK checks it (the method, user and ref are what you asked for, and the key is yours) and signs it. The network then pays its gas and sends it. release doesn't need your key: it only returns credits to the user.
Money and reporting
| Call | What it does |
|---|---|
payout() | Pays unpaid earnings in USDT to your payout account |
activity() | Everything that happened in your app, newest first |
exportCsv() | The same, as CSV |
gas() | Transactions and gas the network spent for you |
setWebhook(url) | Sets your endpoint and returns a new signing secret |
webhookDeliveries() | Recent deliveries and their status |
Webhooks and errors
verifyWebhook(rawBody, signatureHeader, secret) checks a delivery and returns the event. See Webhooks.
Failures throw CreditsError with code, status, isDeclined and isRetryable. See Errors.
Public data
CreditsNetwork needs no key:
import { CreditsNetwork } from "kredo";
const network = new CreditsNetwork({ baseUrl: process.env.CREDITS_API_URL });
await network.reserves(); // the vault's USDT against what it owes
await network.directory(); // every app, with prices and profileIt also has health() and stats().