SDK
Every export of @plaza/sdk 0.2.0, from the one-line spend calls to the tree, proof and instruction builders under them.
@plaza/sdk runs in the browser and in Node 22. It derives holder keys from one wallet signature, scans for notes, builds membership paths from published leaves, proves both proofs locally and sends spends through the relayer. Holder keys never leave the process.
Install
The SDK and the contract it depends on are packages in the Plaza repository, backend/sdk and backend/contract. Pack both and install the tarballs:
npm pack ./backend/contract ./backend/sdk
npm install ./plaza-contract-0.1.1.tgz ./plaza-sdk-0.2.0.tgzTwo entry points:
| Import | Runs in | Adds |
|---|---|---|
@plaza/sdk | Browser and Node | Everything below |
@plaza/sdk/node | Node | loadKeypair, submitManagement, createClient |
createPlaza
createPlaza({ apiUrl }: { apiUrl: string }): PlazaReturns a client bound to one Plaza API. Plaza holds at most one unlocked session; its money methods act on that session and throw PlazaError at stage build with "Unlock the wallet first." before unlock.
| Method | Returns |
|---|---|
unlock(wallet: UnlockOptions) | Promise<PlazaSession>. A new unlock destroys the previous session. |
deposit(args, opts: WalletOptions) | Promise<string>, the confirmed signature |
transfer(args: Transfer, opts?) | Promise<string> |
withdraw(args: Withdrawal, opts?) | Promise<string> |
ragequit(args: Exit, opts?) | Promise<string> |
unlock
wallet.addressstringrequired- The wallet's address.
wallet.signMessage(message: Uint8Array) => Promise<Uint8Array | { signature, signedMessage? }>required- Signs Plaza's unlock message. Wallet Standard's
{ signature, signedMessage }result is accepted as is.
The SDK checks the signature against address and that signedMessage, when given, is the unlock message, then derives the holder keys and zeroes the signature. It reads the cluster from GET /config; on localnet the API must be on a loopback address.
PlazaSession
| Member | What it is |
|---|---|
address | The wallet address |
shieldedAddress | This wallet's Plaza receive address, padded base64. Others send to it with transfer. |
scan() | Promise<Note[]>: every Plaza note the keys open, with status per set. Concurrent calls share one scan. |
deposit, transfer, withdraw, ragequit | As on Plaza |
destroy() | Drops the keys and cancels work in flight. Every later call throws. |
Note
idstring- The note's commitment, hex. Pass
{ id }to a spend. labelstring- The label, decimal.
mintstring- The mint. SOL is the wrapped SOL mint.
amountstring- Base units.
spentboolean- Whether its nullifier is on chain.
setsRecord<string, string>- Status per ASP account:
approved,pendingorrejected.
Money calls
deposit
mintstringrequired- The mint. Use the wrapped SOL mint for SOL.
amountbigint | stringrequired- Base units, a positive u64.
The second argument is WalletOptions: the wallet signs and pays. The SDK checks the transaction the API built (depositor, mint, amount and that the note is addressed to this session) before asking the wallet to sign.
transfer
note{ id: string }required- An unspent note from this session's last scan.
tostringrequired- The recipient's
shieldedAddress. amountbigint | stringrequired- Base units, at most the note's amount. The rest returns to you as change.
setstringrequired- The ASP account to prove against. The note must be approved in it.
withdraw
note{ id: string }required- An unspent note from this session's last scan.
tostringrequired- The destination address.
amountbigint | string- Base units. Omitted: the whole note.
setstringrequired- The ASP account to prove against. For a venue destination, one the venue accepts.
ragequit
note{ id: string }required- The note to exit. It pays out in full to the address that deposited it.
transfer, withdraw and ragequit take ProgressOptions and need no wallet signature: the relayer pays and signs. Each fetches the set's current root and its leaves (or, for a ragequit, the deposit tree), checks the leaves hash to the root, downloads the circuit files, proves, and relays.
Options and progress
type Progress = 'building' | 'signing' | 'proving' | 'relaying' | 'confirmed'
type ProgressOptions = { onProgress?: (stage: Progress) => void }
type SignTransaction = (wire: Uint8Array) => Promise<Uint8Array>
type WalletOptions = ProgressOptions & { signTransaction: SignTransaction }A deposit reports building, signing, confirmed. A relayed spend reports building, proving, relaying, confirmed.
PlazaError
Every failure is a PlazaError with:
stageFailureStage- Where it failed:
build,wallet rejected,proving,simulation,sendorchain refused. messagestring- The stage, then the reason.
programErrorstring | undefined- The program error's name, such as
RootOutsideWindow, when the program refused. See Errors.
Trees and labels
| Export | What it does |
|---|---|
initializePoseidon() | Loads the Poseidon hasher. Call once before the functions below. |
AssociationTree(leaves: bigint[]) | Builds a depth-32 tree. .root is the root; .path(label) returns { siblings, direction } and throws when the label is absent. Leaves must be non-zero, distinct and at most 4,294,967,296. |
depositLabel(depositor, mint, amount, slot, nonce) | The label the program computes for a deposit. |
hashFields(...values: bigint[]) | Poseidon over BN254 field elements. |
fieldBytes(value: bigint) | A field element as 32 bytes big-endian. |
publicKeyLimbs(key: string) | An address as two 128-bit field elements. |
DEPTH, FIELD_ORDER | 32 and the BN254 scalar field order. |
Proofs and instructions
For building flows the one-line calls don't cover:
| Export | What it does |
|---|---|
proveMembership(witness, wasm, provingKey) | Proves the Membership circuit. Returns { proof, publicSignals, bytes }. |
buildDeposit({ depositor, mint, amount, ownerHash, viewingKey, sourceTokenAccount?, tokenProgram? }) | The deposit instruction. |
buildSpend(input: SpendInput) | Proves and builds a transact or ragequit instruction. Returns { instruction, proofMs, sppProofMs }. |
plazaPda(seed, ...fields) | A Plaza program-derived address. |
aspAddress(authority), venueAddress(destination) | The Asp and Venue accounts. |
initInstruction(admin, recipient, feeBps, window = 32) | init |
setFeeInstruction(admin, recipient, feeBps) | set_fee |
registerAspInstruction(authority, name, uri) | register_asp |
publishRootInstruction(authority, root, members, digest) | publish_root; root and digest are 32 bytes, members an integer from 0 to 4,294,967,295. |
clearRootsInstruction(authority) | clear_roots |
registerVenueInstruction(authority, destination, accepted) | register_venue |
setAcceptedInstruction(authority, destination, accepted) | set_accepted |
depositEnvelope, spendEnvelope | Wrap SPP's wire data and accounts into a Plaza instruction. |
signAndSubmit(api, build, opts) | Builds through the API, signs with opts.signTransaction, submits and follows to confirmation. |
Instructions are @solana/kit Instruction objects. Arguments and accounts are on Program instructions.
Node entry
| Export | What it does |
|---|---|
loadKeypair(path) | Reads a Solana CLI keypair file and returns { address, signMessage, signTransaction }, which fits both unlock and WalletOptions. |
submitManagement(api, build, expected, wallet, venueMemo?) | Builds an ASP or venue transaction through the API, refuses it unless its instruction equals expected, then signs and submits. The CLI uses it for every operator command. |
createClient(baseUrl) | The typed API client from @plaza/contract; see API. |