InviaInvia
App
SDK/Quickstart

Quickstart

The shortest path from pnpm add to a settled fill on devnet. The snippets below assume a Privy-shaped wallet adapter, but the SDK works with any signer that exposes the same shape.

1. Construct a client

import { Connection } from "@solana/web3.js";
import { InviaClient } from "@invia-app/sdk";

const connection = new Connection("https://api.devnet.solana.com", "confirmed");

const invia = new InviaClient({
  connection,
  apiBaseUrl: "https://api.invia.markets",
});

The InviaClient exposes two children:

2. Read live offers

const { offers } = await invia.api.getOffers({ status: "open", limit: 25 });
for (const o of offers) {
  console.log(o.side, o.tokenMint, "for", o.pricePerToken, "scale", o.priceScale);
}

3. Post a sell offer

import { PAYMENT_MINTS, parseTokenAmount, pickPriceAndScale } from "@invia-app/sdk";
import { PublicKey } from "@solana/web3.js";

const tokenMint = new PublicKey("Es9...");
const sizeRaw = parseTokenAmount("100", 6);
const totalRaw = parseTokenAmount("0.5", 9);

const priced = pickPriceAndScale(sizeRaw, totalRaw);
if (!priced) throw new Error("Total or size out of expressible range");

const { signature, offer } = await invia.program.createOffer(wallet, {
  side: "sell",
  tokenMint,
  paymentMint: PAYMENT_MINTS.WSOL,
  size: sizeRaw,
  pricePerToken: priced.pricePerToken,
  priceScale: priced.priceScale,
  minFill: sizeRaw,
  expiresAt: BigInt(Math.floor(Date.now() / 1000) + 24 * 3600),
});

console.log("Offer", offer.toBase58(), "tx", signature);

4. Take an offer

const target = offers[0]!;

const { signature } = await invia.program.takeOffer(wallet, {
  offer: new PublicKey(target.pda),
  maker: new PublicKey(target.maker),
  tokenMint: new PublicKey(target.tokenMint),
  paymentMint: new PublicKey(target.paymentMint),
  fillAmount: BigInt(target.minFill),
});
Always simulate first

In production you typically simulate the assembled transaction against the cluster before prompting your wallet. Use your own RPC's simulateTransaction with the same base64 bytes you would send.

What next