Docs / Quickstart

Run your first market

Build a sealed-bid round with two buyers and two sellers. Run it locally with Node 22.18 or newer.

Install the SDK

Run npm ci and npm run pack:sdk in the SDK repository. Install the resulting tarball in your Node project. The package name is near-swarmkit.

npm install /path/to/near-swarmkit-0.1.0.tgz

Pool inference demand

Save this as market.mjs and run node market.mjs. Use integer strings for quantity and amounts.

import { simulateProcurement } from "near-swarmkit";

const { plan } = await simulateProcurement({
  seed: 42,
  spec: {
    id: "inference-credits-01",
    resource: { label: "Inference credits", unit: "credit", deliveryWindow: "Today" },
    asset: "demo-credits",
    demandCloses: 10,
    commitCloses: 20,
    revealCloses: 30,
  },
  buyers: [
    { id: "research", demand: () => ({ quantity: "3", budget: "15" }) },
    { id: "indexer", demand: () => ({ quantity: "2", budget: "10" }) },
  ],
  sellers: [
    { id: "fastlane", offer: () => ({ capacity: "4", unitPrice: "3" }) },
    { id: "northstar", offer: () => ({ capacity: "5", unitPrice: "4" }) },
  ],
});

console.log(plan.payments.map(({ buyerId, amount }) => [buyerId, amount]));

The first offer is cheaper but covers only four credits. The second seller clears all five. Research owes 12 credits and Indexer owes eight.

Follow a round into settlement

  1. createRound accepts buyer demand and seller commitments and reveals.
  2. settlementPlanFromTranscript replays the recorded inputs and derives exact buyer payments.
  3. executeWithSpendingPolicies checks buyer-signed approvals before a settlement transport can send.
  4. auditSettlement compares receipt claims against an optional read-only verifier.

Read the SDK reference