The npm package ships both the TypeScript wrapper (dist) and the wasm-bindgen
artifacts generated by wasm-pack (native/pkg for Node, native/pkg-web for browsers).
- Run
npm run buildto produce all outputs locally (node wasm, web wasm, TS builds). npm pack/npm publishtrigger the same build through theprepackscript, ensuring the JS glue +.wasmblobs are always included in the tarball.- Verify the contents with
npm pack --dry-runafter a build.
import { Curve } from "pbcurve/node"; // or `const { Curve } = require("pbcurve");`
const DECIMALS = 10n ** 8n;
const cfg = {
total_supply: 1_000_000n * 10n ** 8n,
sell_amount: 500_000n * 10n ** 8n,
vt: 250_000n * 10n ** 8n,
mc_target_sats: 10_000_000n * 10n ** 8n,
};
const curve = (await Curve.create(cfg)).expect("curve init failed");
const price = curve.snapshot(0n).expect("snapshot").x;
const raised = curve.cumulativeQuoteToStep(100_000n * DECIMALS).expect("quote");import { initWebCurveWasm, Curve } from "pbcurve/web";
await initWebCurveWasm(); // optional: pass your own fetch/URL/Response
const DECIMALS = 10n ** 8n;
const cfg = {
total_supply: 1_000_000n * 10n ** 8n,
sell_amount: 500_000n * 10n ** 8n,
vt: 250_000n * 10n ** 8n,
mc_target_sats: 10_000_000n * 10n ** 8n,
};
const curve = (await Curve.create(cfg)).expect("curve init failed");
const quote = curve.quoteInGivenAssetOut(0n, 1_000n * 10n ** 8n).expect("quote");
const raised = curve.cumulativeQuoteToStep(25_000n * DECIMALS).expect("quote");initWebCurveWasm accepts anything wasm-pack’s loader does (URL, Request, Response, or an ArrayBuffer/Module), so you can hook it into your bundler/asset pipeline easily. Subsequent Curve.create calls reuse the initialized module automatically.
Call curve.mcSatsAtStep(step) to estimate the FDV (in sats) at any point on the curve. It runs inside the wasm core so you avoid duplicating the math in JS/TS.
Next.js' Turbopack loader still cannot bundle .wasm modules that wasm-pack emits. The package therefore ships a pbcurve/next entry point that lazily fetches the WebAssembly blob at runtime:
- When you install
pbcurve, apostinstallhook copiesnative/pkg-web/curve_wasm_bg.wasminto your app's existingpublic/pbcurve/directory (it only runs if apublic/folder is present, so Node-only apps are untouched). Commit that file so deployments can serve/pbcurve/curve_wasm_bg.wasm. If you disable npm scripts or do not have apublic/directory, copy the file manually:cp node_modules/pbcurve/native/pkg-web/curve_wasm_bg.wasm public/pbcurve/. - Import from
pbcurve/nextand pass the public URL of the wasm file each time you create a curve (usually/pbcurve/curve_wasm_bg.wasm). The factory fetches + instantiates the module once and reuses it afterwards.
import { Curve } from "pbcurve/next";
const DECIMALS = 10n ** 8n;
const cfg = {
total_supply: 1_000_000n * DECIMALS,
sell_amount: 500_000n * DECIMALS,
vt: 250_000n * DECIMALS,
mc_target_sats: 10_000_000n * DECIMALS,
};
const wasmUrl = "/pbcurve/curve_wasm_bg.wasm";
const curve = (
await Curve.create(cfg, {
wasmUrl,
// optional: fetch, requestInit
})
).expect("curve init failed");
const price = curve.snapshot(0n).expect("snapshot").x;Pass a custom fetch implementation (and requestInit) if you need authenticated fetches or want to run the loader from within a different runtime like Next.js Route Handlers. Relative URLs are resolved against window.location.origin, so on the server (or during next dev’s SSR pass) you must provide an absolute wasmUrl or guard the initialization so it only runs in the browser.