@nyen/sdk
v0.1.2
Published
Official TypeScript SDK for the NYEN /v1 public API — reads, satoshi-safe amounts, NTS token ops, unsigned tx build, broadcast, SSE events, HMAC webhooks, and Wallet Connect signing (Login-with-NyenID).
Maintainers
Readme
@nyen/sdk
⚠️ TESTNET — data resets at mainnet launch. The live
/v1API currently serves an ephemeral test chain. Addresses, txids, and token ids you see now are wiped when mainnet goes live — don't hard-code them. Checknetwork/mainneton/v1/chainor/v1/health(reads"testnet"until launch).
Official TypeScript SDK for the NYEN /v1 public API. Zero runtime deps,
isomorphic (browser + Node ≥18). Wraps the read gateway (chain/block/tx/address/
token/fee reads), unsigned tx build, signed broadcast, SSE events, HMAC webhooks,
and — in the browser — Wallet Connect signing (Login-with-NyenID, token send).
Security spine (unchanged from the API): read is open, the only server-side write is broadcast of an already-signed tx, and signing happens in the user's wallet — the SDK never holds keys.
Install
npm install @nyen/sdkRead a balance + send a token in < 20 lines
import { NyenClient } from "@nyen/sdk";
import { NyenWallet } from "@nyen/sdk/wallet";
const nyen = new NyenClient({ baseUrl: "https://nyen.cc/v1", apiKey: "pk_…" });
// read (keyless, any address) — amounts are satoshi-exact, never floats
const { native, tokens } = await nyen.address("N9x…");
console.log(native.balance, "NYEN");
for (const t of tokens) console.log(t.balance, t.name);
const quote = await nyen.feeEstimate("tokentransfer"); // { fee, feesat, basis }
// send an NTS token — signed + broadcast in the desktop wallet (browser only)
const wallet = new NyenWallet();
await wallet.connect("My dApp"); // Approve dialog in wallet
const result = await wallet.sendToken({ to: "R7y…", token: "MYTOKEN", amount: "10" });
console.log("sent", result, "fee ~", quote.fee);Login-with-NyenID (D30)
const wallet = new NyenWallet();
await wallet.connect("My dApp");
// `nonce` comes from your server
const { ok, address, signature } = await wallet.loginWithNyenId(nyen, nonce);
// POST { address, signature, nonce } to your server; it re-verifies + issues a sessionLive events (SSE)
const stop = nyen.subscribe({
channels: ["block", "address:N9x…"],
onEvent: (e) => console.log(e.type, e.data),
});
// …later
stop();Webhooks (server-side)
const hook = await nyen.createWebhook({ url: "https://me.com/hook", events: ["deposit.confirmed"] });
// store hook.secret NOW — shown only once. Then verify each delivery:
const ok = await NyenClient.verifyWebhookSignature(
hook.secret, req.headers["x-nyen-timestamp"], rawBody, req.headers["x-nyen-signature"],
);Errors
Every failure throws a typed NyenError with a stable string code
(tx-rejected, insufficient-funds, rate-limited, …), the daemon's verbatim
reason, a plain-English hint, and a docs link. err.retryable flags
rate-limit / upstream errors worth retrying.
Build from source
npm install && npm run build # -> dist/ with .js + .d.tsTypes mirror the API's OpenAPI schema (GET /v1/openapi.json).
