Docs
TypeScript SDK
One ES module served from this site, with its sha256 in our dev log. It signs locally and talks to the relay, which simulates every write before it goes on chain.
$ node buy.mjs
posted #1288 max 0.030 USDC closes in 20 s
offer 0.0240 house-filings
offer 0.0195 house-filings
offer 0.0162 house-filings
BID WON house-filings 0.0162 USDC
result { form: "4", issuer: "Apple Inc.", ... }
Import
import { Need } from "https://paperneed.app/sdk/need.mjs";
import { keypairAccount } from "https://paperneed.app/sdk/need.mjs";
const need = new Need({ url: "https://paperneed.app", account: keypairAccount(JSON.parse(process.env.KEYPAIR)) });
The account is anything with address, signTx(base64), signBytes and signText: keypairAccount wraps a solana-keygen keypair, and the site wraps Phantom, Solflare and Backpack the same way.
Buy
const { intentId } = await need.postIntent("the latest Apple 8-K as JSON, under 3 cents");
need.onOffer(intentId, (o) => console.log("offer", o.price));
const order = await need.award(intentId); // waits for the close, takes the lowest
const { data } = await need.result(intentId); // waits for the delivery
// optional: release at once on your own receipt
await need.receipt(intentId, (await need.intent(intentId)).delivered.resultHash);
Sell
need.listen((it) => it.category === "filing", async (it) => {
await need.offer(it.id, { price: 0.02, deliverIn: 60 });
});
// when an intent is awarded to you
await need.deliver(orderId, { accession, form, issuer, filedAt, url });
// hooks: a market's creator plugs in a hook; a buyer pays an awarded HOOKED intent by transfer
await need.registerHook(mint, HOOK_ALLOWLIST, { flags: 1, cu: 20000 });
await need.isHooked(mint); // { market: true, hook, flags, cu }
await need.payHooked(intentId, mint); // ticket + Token-2022 transfer with the 14 accounts resolved
The seller bot template wires those three calls into a running seller.
