Pando Exchange Docs Build your marketplace
On this page

API reference

API recipes

Use the API to display a floor, follow the book and inspect a prepared listing.

Display a floor and ten cheapest fixed listings#

Use collection metadata for the aggregated floor. Page /items and retain fixed rows ordered by price. The floor can come from an NFTX pool even though the table shows fixed listings. Use textContent when displaying strings from the API.

js
const market = "https://marketplace.example";
const collection = "/v1/collections/1/0x4a8b01e437c65fa8612e8b699266c0e0a98ff65c";

async function read(path) {
  const response = await fetch(market + path);
  if (!response.ok) throw new Error(`Marketplace request failed (${response.status})`);
  return response.json();
}

function eth(wei) {
  const n = BigInt(wei);
  const unit = 10n ** 18n;
  const fraction = String(n % unit).padStart(18, "0").replace(/0+$/, "");
  return String(n / unit) + (fraction ? "." + fraction : "");
}

const metadata = await read(collection);
const listings = [];
let cursor;
do {
  const query = new URLSearchParams({ limit: "50", sort: "low" });
  query.append("venue", "native");
  query.append("venue", "opensea");
  if (cursor) query.set("cursor", cursor);
  const page = await read(collection + "/items?" + query);
  listings.push(...page.data.filter((row) => row.priceKind === "listing" && !row.variablePrice));
  cursor = page.nextCursor;
} while (listings.length < 10 && cursor);

document.querySelector("#floor").textContent = metadata.floor
  ? `${eth(metadata.floor.takerWei)} ${metadata.floor.currency}`
  : "Floor unavailable";
const rows = listings.slice(0, 10).map((listing) => {
  const row = document.createElement("li");
  row.textContent = `#${listing.tokenId} · ${eth(listing.takerWei)} ${listing.currency}`;
  return row;
});
document.querySelector("#listings").replaceChildren(...rows);

Follow the book#

Use each pushed depth as the current display. After a disconnect, wait for a fresh snapshot. The function returns a cleanup callback for page navigation.

js
function followBook(onDepth, setStatus) {
  let socket;
  let retry;
  let stopped = false;
  function connect() {
    socket = new WebSocket("wss://marketplace.example/v1/collections/1/0x4a8b01e437c65fa8612e8b699266c0e0a98ff65c/ws");
    socket.onmessage = (event) => {
      const message = JSON.parse(event.data);
      if (message.type === "snapshot" || message.type === "delta") {
        setStatus("Current");
        onDepth(message.depth);
      }
    };
    socket.onclose = () => {
      if (stopped) return;
      setStatus("Waiting for a fresh snapshot");
      retry = setTimeout(connect, 3000);
    };
  }
  connect();
  return () => {
    stopped = true;
    clearTimeout(retry);
    socket?.close();
  };
}

Inspect a prepared listing#

Supply the actual holder’s address. The template checks ownership, payout, approval and admission before it returns the next wallet action. This example stops at displaying that action.

js
const market = "https://marketplace.example";
const collection = "/v1/collections/1/0x4a8b01e437c65fa8612e8b699266c0e0a98ff65c";
const seller = "0x1111111111111111111111111111111111111111"; // Replace with the holder’s address.
const response = await fetch(market + collection + "/listings/prepare", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ seller, tokenId: "344", priceWei: "10000000000000000" }),
});
const review = await response.json();
if (!response.ok) throw new Error(review.error.message);
if (review.walletEnabled && review.approval) {
  console.log(review.approval.label, review.approval.to);
} else if (review.walletEnabled && review.typedData) {
  console.log(review.typedData.domain, review.typedData.message, review.amounts);
}

Note. If the holder needs approval, the holder’s wallet signs and sends the collection’s setApprovalForAll(conduit, true) call. After the receipt, prepare again. When approval is current, the holder signs the Seaport 1.6 EIP-712 OrderComponents message, including the NFT, payout recipients and amounts, expiry, conduit key, counter and salt. The signature authorizes filling that order on its stated terms. The server never signs or sends a transaction.

Pando Exchange is software published by Simple Things Ltd. Each marketplace made with it is run by its operator, in the operator's own account.