SDK/Guides

Sale rooms with the SDK

TESTNETPREVIEW

The whole sealed sale room runs on the SDK's exports: a seller opens a room, agents bid by address with a membership pass, wallets bid privately through the shielded pool and a relayer, and the seller finishes the room after the close. Nobody can read a price until bidding closes. See Sealed rooms for how a sale room works.

1. The configuration#

TypeScript
import { TESTNET_SALE_ROOM, TESTNET_POOL, TESTNET_RELAYER } from "@esseyonsui/sui-sdk";

TESTNET_SALE_ROOM is the live package 0x48db0307be9b6aadbf9f29c28561e1b450348ab2786ea4853a8d7249c22979a1: its PassKey, the three key servers its room.move pins (Mysten's two testnet servers, then its committee server), in that order, and threshold 2. A bid sealed to any other list or order is refused (room abort 7), so you never assemble this yourself. saleRoomOf(record, { keyServers, threshold }) reads another deployment record.

The committee server only answers through its aggregator, and Seal refuses an aggregator on any other server; saleSealClient(client, cfg) sets both. TESTNET_POOL is the package's shielded SUI pool, and TESTNET_RELAYER the hosted relayer on the SUI pool's route, its address and its smallest fee, 10,000,000 MIST. The USDC and Sui Dollar routes (/relay/usdc, /relay/usdsui) take their fees in that pool's coin, smallest fee 10,000 base units. The SDK exports no Relayer for those two routes: build one from relayer in GET /v1/private/config, as Private flows shows. Each floor is set in the relayer's own configuration and the API does not serve it; a fee under it is refused before anything is signed, as sendToRelayer's { ok: false, error: "fee below MIN_FEE", sent: "no", from: "relayer" }.

2. The seller#

TypeScript
import { EsseySeller } from "@esseyonsui/sui-sdk";

const seller = new EsseySeller({ chain, signer: sellerKey, saleRoom: TESTNET_SALE_ROOM, poolId: TESTNET_POOL.pool });
const { badgeId } = await seller.mintBadge("lot 1");          // the package's demo item
const { roomId } = await seller.open(
  { id: badgeId, type: `${TESTNET_SALE_ROOM.pkg}::demo::Badge` },  // any key+store object you own
  { minPrice: 1_000_000n, maxPrice: 10_000_000n, closeMs, maxBids: 5 },
);
const sellerPass = await provedPassFor({ service, holder: sellerKey.toSuiAddress(), room: roomId, secrets, hash, paths });
await seller.attest(roomId, { tag: sellerPass.tag, expiryMs: sellerPass.credential.expiryMs, proof: sellerPass.proof });

open does not take bids. The next transaction is seller.attest(roomId, pass) (or openAndAttest, which proves the pass for the new room id and attests). Until that lands, every bid aborts 23 ESellerNotAttested (SELLER_NOT_ATTESTED before signing). The pass is the seller's own sender-bound credential for the new room id. open refuses before signing what room.move would refuse (room abort 10): a floor of 0 or above the ceiling, a close in the past, more than 50 bids, a finish window under 30 minutes. A room takes one kind of bid. shieldedOnly: false (the default) opens an address room: agents bid by address with a pass, and a pool bid is refused on chain (room abort 17, ENotShieldedRoom). shieldedOnly: true opens a shielded room: only pool bids land, and an address bid is refused (room abort 16, EShieldedRoom). In the v2 view (readSaleRoomV2) pool is the shielded pool the room's bids come from: null until a pool bid, or the seller's shielded payout note, names it, so an address room's bids never set it.

3. Address bids#

TypeScript
const service = new EsseyService(api, agentKey);
await service.signIn();
const pass = await provedPassFor({ service, holder: agentKey.toSuiAddress(), room: roomId, secrets, hash, paths });   // the service's credential, proved on this machine
const agent = await EsseyAgent.start({ chain, deployment, signer: agentKey, account, gas: "coins", saleRoom: TESTNET_SALE_ROOM });
const landed = await agent.bidSaleRoom(roomId, 4_000_000n, pass);   // 0.004 SUI, sealed; deposit = the ceiling

The seller must have attested first. saleBidTx and bidSaleRoom build the live room::bid: room, Access, gate (null while Access is PUBLIC), membership, sealed price, max-price deposit, clock. The deposit is not taken from the gas coin. A dry run runs before the signature, including when a gas budget is set, so an arity mismatch is WOULD_ABORT and is not sent.

provedPassFor asks the service to sign the member's commitment, then proves membership on this machine; the issuer never sees the secrets. Its arguments:

  • service: a signed-in EsseyService. Its credential(commitment) is POST /v1/agent/credential. Any key signs in there (signIn runs /v1/agent/challenge and /v1/agent/session): the route needs a session, not an account, and the commitment is pinned to the session's address.
  • holder: the address that sends the bid. Without binding, the pass is bound to it.
  • room: the room id. A deposit pass names the pool id instead.
  • secrets: { secret, nullSecret }, two field elements below the BN254 scalar field order, each drawn from 31 random bytes on the member's own machine. persistentMemberSecrets(store, () => randomBytes(31)) does this: it reads them from store ({ get(): string | undefined; set(v: string): void }, your own file or keychain entry) and draws and saves them, as decimal strings, only when the store is empty. Make them once and keep them like a key: the issuer pins the first commitment it signs for an account, and a different commitment answers 409 ALREADY_ISSUED. Never derive them from an address or a seed a server knows: whoever knows nullSecret can link the member's bids across rooms.
  • hash: Poseidon over BN254, poseidonHash from @mysten/sui/zklogin.
  • snarkjs (optional): omit it; the SDK loads the snarkjs 0.7.6 it depends on. Pass a module only to use another one.
  • paths: { wasm, zkey } of the membership circuit: (await fetchProofBundle({ baseUrl, dir })).membership, with baseUrl the folder of the proving-keys manifest, https://cdn.jsdelivr.net/npm/@esseyonsui/proving-keys-testonly@0.1.0.
  • nonce: omit for a room bid (0). A deposit pass passes a fresh field element, so the tag does not repeat.
  • binding: omit for a sender-bound pass (room::bid, pool::deposit). { n0 } binds the pass to a pool spend's first nullifier, for pool::bid, which checks that the spend's n0 matches.
  • vkey (optional): the circuit's verifying key; with it the proof is checked locally before anything is sent.

The result is a ProvedPass (holder, tag, proof, credential, nonce). bidSaleRoom turns it into a Membership with membership::from_proof in the same transaction as the bid.

bidSaleRoom reads the room and the on-chain PassKey, and refuses before sealing, with an EsseyError, every bid the chain would refuse, in the chain's own order:

refusalchain abort
the credential is for another address, was signed under another issuer key, or for another epoch than the PassKey holdsmembership 1
the credential has expiredmembership 2
the tag is not a canonical field elementmembership 4
the room takes shielded bids onlyroom 16
this address has already bidroom 15
the room has ended, or bidding has closedroom 2, room 3
the room is fullroom 6
the price is outside the floor and ceilingnone: the chain takes it and the finish drops it
the ciphertext names other key servers, another order, threshold, room or bidderroom 7
the bidder is the room's sellerSELLER_CANNOT_BID before signing; on chain, room 20

4. The finish#

TypeScript
const landed = await seller.finish(roomId);                    // any two servers that answer, in KEY_SERVERS order
const landed = await seller.finish(roomId, { servers: [0, 2] });   // or exactly these two
const outcome = await seller.outcome(landed.digest);           // winner, price, bids, valid, sharesHandedIn, balanceChanges

After the close, finish asks the key servers for the room's derived keys under a session the seller's key signs, and hands exactly two shares: every share costs finish gas per bid, and a 50-bid finish with all three keys would not fit one transaction. It dry-runs the finish first and refuses with OVER_GAS_CAP if it would pass the 5,000,000-unit computation cap. It refuses a room still open (room abort 4), already ended (room abort 2), or a sender who is not the seller (room abort 8). finish is the seller's to send once the room has closed.

At the finish the highest valid price wins: the seller gets it, the winner gets the item and the rest of its deposit, and every other deposit goes back. expire(roomId) ends an address room nobody finished once its finish window has passed (room abort 11 before): every address deposit goes back in that transaction and the item returns to the seller. A v2 expire (expireSaleV2Tx) also returns the item, and it returns address deposits the same way, but each shielded deposit stays pending until someone sends collectTx (below).

5. Private bids#

TypeScript
import { ShieldedWallet, snarkjsProver, graphqlEventBcs, TESTNET, wirePass } from "@esseyonsui/sui-sdk";

const prover = await snarkjsProver({ snarkjs, wasm, zkey });
const setup = { client: chain.client, events: graphqlEventBcs(TESTNET.graphqlUrl), room: TESTNET_SALE_ROOM,
                pool: TESTNET_POOL, relayer: TESTNET_RELAYER, prover: prover.prover, indexed: chain.indexed };
const { wallet, seed } = ShieldedWallet.create(setup);        // keep the seed; it is the whole wallet
const again = ShieldedWallet.fromSeed(seed, setup);            // restore anywhere

const credential = async (n0: bigint) => ({
  gate: null,                                                   // Access is PUBLIC; otherwise wirePass of the Access pass, bound to n0
  member: wirePass(await provedPassFor({
    service, hash: poseidonHash, paths, holder: bidder, room: room.id, secrets, binding: { n0 },
  })),
});
await wallet.bid(room, price, claimTo, nowMs, fee, credential);
  • Deposit. wallet.depositTx(depositor, pass, amount, nowMs) builds a deposit from a wallet that holds a pass. The coin is the amount plus the pool's insert fee F (0.1 SUI, 0.01 USDC or 0.01 tUSDsui on testnet), which the pool keeps. SUI, USDC and tUSDsui are all drawn with coinWithBalance({ useGasCoin: false }), so faucet SUI sitting in the address balance is enough: the transaction withdraws it with 0x2::coin::redeem_funds and does not split the gas coin. It refuses an amount of 0, a pass the chain would refuse, and a wallet whose total, coin objects or address balance cannot pay amount + F. The refusal says which of those is short.
  • Scan. wallet.scan() reads every NewCommitment and every NewNullifier of the pool and returns the notes this seed owns, spent ones included (each has spent), and the balance of the unspent ones: after a full exit the notes are still listed and the balance is 0. Restored from the seed alone, a wallet sees exactly what it had, refunds included.
  • Bid. wallet.bid(room, price, claimTo, nowMs, fee, credential) seals the price, proves the spend and sends it to the relayer, which signs and pays for the transaction: the bidder's wallet never appears. credential is required. It is (n0) => ({ gate, member: wirePass(await provedPassFor(...)) }), the shape in the snippet above, bound to that spend's n0. member is the room credential. gate is null while Access is PUBLIC, otherwise wirePass of the Access pass bound the same way. The raw ProvedPass is not the credential: the relayer serializes wirePass. The relayer refuses a bid without member. A bid needs one or two notes worth max_price + fee + 2F, because the pool inserts a change note and a refund note and charges F for each. On the testnet SUI pool F is 0.1 SUI and the relayer fee is 0.01 SUI, so a small bid (max price 0.002 SUI) needs about 0.212 SUI already in the pool, and depositing that note costs another 0.1 SUI. A loan offer is the same shape with the principal in place of max_price. It refuses before proving an unattested seller (SELLER_NOT_ATTESTED, room abort 23), an address room (room abort 17), a closed or full room, a price out of range, a fee under the relayer's minimum, and a room opened by an address this user owns (ShieldedSetup.ownAddresses, or one this wallet deposited from). On a stale tree, or the relayer's STALE_ROOT, it rescans and proves again.
  • Refund. A losing bid's deposit goes back into the pool with collectTx({ ...pool, pkg: cfg.pkg }, view), which anyone may send. cfg.pkg is the sale package (TESTNET_SALE_ROOM.pkg, or saleRoomV2.pkg for a v2 room), the same call as Private flows. pool alone is the privacy package, and collectTx(pool, view) looks for room::collect there and does not find it. After a v2 expire, each shielded deposit stays pending until someone sends that collectTx once per bid. Expire returns the item to the seller and does not insert the notes. The next scan finds a collected note from the seed.
  • Win. The winner's item and change wait in the room; claimTx(cfg, room, claimTo, wallet.claimSalt(tag)), sent by anyone, delivers them to the claimTo the bid sealed.
  • Withdraw. wallet.withdraw(recipient, amount) pays out through the relayer and keeps the change as a note (one insert fee); wallet.exit(recipient) pays out everything left, less the relayer's fee, and inserts nothing. Exit is refused when the unspent notes are not strictly more than the fee. On SUI that fee is 0.01 SUI, so a note of exactly 0.01 SUI cannot be exited. See Withdraw and exit.

The proving key is a TEST-ONLY single-party setup: fine for testnet, not for value. The ceremony key replaces it. The prover is configured by path (snarkjs, the circuit's wasm and zkey). Poseidon defaults to @mysten/sui/zklogin's poseidonHash, which is circomlib's.

Gas#

The sponsored lane does not take sale-room calls. An agent pays from its own SUI: in coins mode one coin of at least 50,000,000 MIST for gas, plus the deposit. A private bid's gas is the relayer's, paid back by its fee.

One faucet grant is about 1 SUI (sui client faucet --url https://faucet.testnet.sui.io --address <ADDRESS>, or https://faucet.sui.io). That covers a bidder's ~0.312 SUI deposit and the deposit transaction's gas, or a seller's open, attest and finish. Finish and settle each ask for a 0.25 SUI gas budget, which must sit in the address balance or in one coin even though the transaction spends less. A SUI loan repayment is owed plus another 0.1 SUI insert fee (about 0.101 SUI for a 0.001 SUI principal). One address that sells, borrows and also deposits the bid and offer notes needs more than 1 SUI: a 0.45 SUI note (enough for the sale bid and, from the change, the loan offer) costs 0.55 SUI to deposit, then the 0.25 SUI finish budget, the 0.25 SUI settle budget and the ~0.101 SUI repayment do not fit in one drip. Request the faucet again for another ~1 SUI. On a rate limit, wait and retry that address, or use another address.

On testnet#

The whole route ran on these exports on 2026-10-30; the run log, every digest re-read through GraphQL, the probes and a terminal recording are in logs/testnet/sdk-full-route-2026-10-30/. Two agents set up through the owner path bid by address in room 0x3c28…b538: A 0.004 SUI (Dzymqb9SNEZpEdoFnHcST6WdCHmCgjS9uBzk9A1aAZ4) and B 0.006 SUI (TwRGyLAPNC59nG8efTNaLFZWP3zt8ZiGyTEVx6CHxMm); A's second bid, sent past the SDK, was refused by the chain with room abort 15 (EeDkJpPc5A78DThzS6Yohm5zMfkh8J8uFjsZJUhqVwU5). The finish handed key servers {0, 2}, Mysten's committee server included (vvYkSyAigSxNy3wSJ49mDLpFSiZtyaAJ3U8C3PDAzXJ): B won at 0.006 SUI, A got its 0.01 SUI deposit back and B its 0.004 SUI change. In the shielded room 0xc1f9…aa7e, two wallets bid through the hosted relayer, C 0.05 SUI (EgCMhjjRuconXegK9qMUTYabCVfzzxgcPAUKav2coALP) and D 0.08 SUI (8ir83LVbrF8XuVhZq3K2yNdWMnH5YM27geBRKbw7QXA); the finish (7ETA9YfKKbwgcfdm24tKChKV5VsocNTJhRaE8eef7NQg) chose D; C's refund was collected (5bcgpTUoFoHF9N7vBoQtsr67qP3V2c6MyfhbJ1bcWiwe) and found by a fresh scan from C's seed alone; D's claim delivered the badge and 0.12 SUI of change (HtHDX4dStr6xWiJdBgR6rSVqZgxPC6RweXdN6R8o3DQZ); C withdrew 0.02 SUI with change (38xobUxXAwwkfyt7pUDiXoDJb7Ur8VP96fHc811VyRX4) and exited the last 0.05 SUI (6g6W9yQGE4JpGzCaMNgGCxoZ7Stj44YoZxUm3UkFpS8J). A room nobody bid in expired (4tRLn1wYUVyU72B66e1bJGDa4d2TZ2E2TYsBaxX1TLRw). 33 probes were each refused: before signing by the SDK, by the relayer, or on chain with the abort the table names.