First spend with the SDK
Unlock, deposit, wait for approval and withdraw from TypeScript with @plaza/sdk.
Install @plaza/sdk as SDK describes. You need a wallet object with address, signMessage and signTransaction: a Wallet Standard wallet in the browser, or loadKeypair in Node.
import { createPlaza } from '@plaza/sdk'
import { loadKeypair } from '@plaza/sdk/node'
const SOL = 'So11111111111111111111111111111111111111112'
const wallet = await loadKeypair('./id.json')
const plaza = createPlaza({ apiUrl: 'http://127.0.0.1:5902' })
// 1. one signature derives the holder keys
const session = await plaza.unlock(wallet)
// 2. deposit 0.01 SOL; the wallet signs and pays
await plaza.deposit({ mint: SOL, amount: '10000000' }, wallet)
// 3. wait until a set approves the new note
const [set] = await fetch('http://127.0.0.1:5902/sets').then((r) => r.json())
let note
while (!note) {
const notes = await session.scan()
note = notes.find((n) => !n.spent && n.sets[set.id] === 'approved')
if (!note) await new Promise((r) => setTimeout(r, 5000))
}
// 4. withdraw the whole note, proven against that set
const signature = await plaza.withdraw({ note, set: set.id, to: wallet.address })
console.log(`receipt: /proof/${signature}`)
session.destroy()What each step does:
unlocksigns Plaza's unlock message and derives your keys in the process.depositbuilds the deposit through the API, checks it, has the wallet sign, and returns once it is confirmed. The note's label ispendingin every set.scanfinds your notes and reads each label's status. The Open Set approves after its screening delay, 30 seconds on localnet.withdrawproves membership against the set's current root, proves the SPP spend, sends both through the relayer and returns the confirmed signature. The receipt is at/proof/followed by it.
For a private payment, use session.transfer({ note, to, amount, set }) with the recipient's shieldedAddress. Every call and type is on SDK.