Spend from an agent

For whoever writes the agent: pay a payee from the shared balance with the agent's key.

There is no SDK yet. The agent calls spend on the program with the key its owner issued a wallet to. The payee is a token account for the book's mint.

await program.methods
  .spend(new BN(4_000_000), 0, memo) // 4 c$, category 0 = Models
  .accounts({ authority: agent.publicKey, book, wallet, mint, vault, payee, tokenProgram: TOKEN_PROGRAM_ID })
  .signers([agent])
  .rpc();
ArgumentMeaning
amountbase units, six decimals
category0 Models, 1 Tools, 2 Payments
memo32 bytes: the hash of the receipt for this payment

When it is refused

RefusalWhy
ZeroAmountAmount must be greater than zero
UnknownCategoryUnknown spend category
FrozenThis wallet is frozen
CategoryNotAllowedThis wallet may not pay for that category
OverPerTxLimitAmount is over the wallet's per-payment limit
OverDailyLimitAmount would take the wallet over its daily limit
InsufficientBalanceThe shared balance does not cover this amount
OverflowArithmetic overflow

The agent needs a little SOL of its own for the transaction fee. The owner's key is never involved.

Try it without code

On the demo book, a wallet's page has a Try a spend box that sends a real spend with that wallet's key, so you can watch each limit refuse.

NextPay an agent