Developer guide / Node SDK

Put recovery inside your app.

Your app tells NeverDown which dependency matters and how to recognize a failure. The SDK raises one incident, your approved backup takes over, and the RPC adapter can replenish capacity under policy.

01 / ObserveRegister a failure spot

Use a health probe or report a meaningful app error.

02 / DecideRaise one incident

Choose a failure threshold to avoid reacting to a single blip.

03 / RecoverSwitch to a backup

Call your approved recovery action before shopping for capacity.

04 / ReplenishProcure under policy

For RPC, verify an offer and request a controlled purchase.

Implementation / any failure spot

How does the SDK know?

It only sees signals you connect. A probe can check reachability; your dApp can report a semantic error that a health endpoint misses. The monitor runs in your Node process and calls your incident handler once per outage.

1. Name the dependency

Use an ID such as price-api, indexer, or rpc-main.

2. Define failure

Return false from a probe, or call reportFailure when data is wrong even though the server responds.

3. Recover first

Your incident callback switches to an approved backup. It can then start replenishment without holding up the fast switch.

app-monitor.ts · server-side TypeScript
import { FailureSpotMonitor } from "@neverdown/sdk";

const monitor = new FailureSpotMonitor();
monitor.register({
  id: "price-api",
  failureThreshold: 2,
  probe: async () =>
    (await fetch("https://prices.example/health")).ok,
  onIncident: async ({ incidentId, reason }) => {
    // Implement these actions in your app.
    await switchToApprovedPriceBackup();
    await replenishPriceBackup(incidentId, reason);
  },
  onError: (error) => console.error(error),
});

monitor.start(5_000);

// Report a bad price even if HTTP still returns 200.
await monitor.reportFailure(
  "price-api",
  "price outside expected range"
);

// Clear the incident after the dependency recovers.
monitor.reportHealthy("price-api");
Implementation / current RPC adapter

Discover, verify, then procure.

The Node SDK discovers Arkiv offers, checks the seller against your ENS allowlist, proves the RPC endpoint works, and asks the isolated payment worker to apply the Resilience Contract. Only the RPC category has a built-in purchase and gateway install adapter today.

Read side

ENS_RPC_URL, ENS_ALLOWLIST_NAMES, and POC_REFERENCE_RPC let the SDK verify identity and capability.

Payment boundary

Keep Hedera signing keys in a protected worker env file. The app passes only PAYMENT_WORKER_ENV_FILE, gateway URL, and gateway token.

Check the result

A settled payment may still fail to install. Inspect receipt.installed and reconcile before retrying.

rpc-recovery.ts · server-side TypeScript
import { NeverDown } from "@neverdown/sdk";

const nd = NeverDown.create({ env: process.env });
const offers = await nd.discoverOffers({
  category: "rpc",
  maxPriceTinybars: 10_000n,
});
const offer = offers[0];
if (!offer) throw new Error("No approved offer");

const seller = await nd.resolveSeller({
  ensName: offer.sellerens,
  expectedPayTo: offer.payto,
});
if (seller.records.x402Url !== offer.serviceurl) {
  throw new Error("Offer URL differs from ENS");
}

const proof = await nd.proveCapability({
  rpcUrl: offer.probeurl,
  expectedChainId: Number(offer.chainid),
  payTo: offer.payto,
  ensPayTo: seller.records.hederaAccount!,
});
if (!proof.pass) throw new Error("RPC proof failed");

const receipt = await nd.procure({
  incidentId: "rpc-main:incident-001",
  serviceId: "rpc-main",
  offer,
});
console.log(receipt.status, receipt.installed);
console.log(receipt.hashscanUrl);
Run it / current release state

What you need to run this.

Node 22.13+ on your server. The SDK is not a browser wallet or a client-side script. Use a private server process for procurement.

Package availability. @neverdown/sdk and @neverdown/core are in the repository but are not yet published to npm. Use the monorepo or build and install both package tarballs.

1 / Configure

Set the ENS and independent RPC read settings. For purchases, configure the protected payment worker file and authenticated gateway.

2 / Connect

Register a dependency probe or report application errors. Supply your approved fast recovery callback.

3 / Verify

Run pnpm sdk:smoke for a read-only live check, then inspect the procurement receipt and evidence.