Node SDK

kredo is the server kit. No dependencies, Node 18 or later.

npm install kredo

Setup

import { Credits } from "kredo";
 
const credits = new Credits({
  apiKey: process.env.CREDITS_API_KEY!,
  signerKey: process.env.CREDITS_SIGNER_KEY, // signs your live charges
});
OptionDefaultMeaning
apiKeyrequiredYour app's live (uc_live_) or test (uc_test_) key
signerKeynoneYour 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
baseUrlhttps://kredo-near-api.onrender.comThe network's API
pagesUrlhttps://kredo-near.vercel.appThe hosted connect, buy and account pages
retries2Extra tries after a network failure or rate limit. Writes are safe to retry: each carries a ref
timeoutMs60000Per 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

CallWhat 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

CallWhat 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

CallWhat 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

CallWhat 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 profile

It also has health() and stats().