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();| Argument | Meaning |
|---|---|
| amount | base units, six decimals |
| category | 0 Models, 1 Tools, 2 Payments |
| memo | 32 bytes: the hash of the receipt for this payment |
When it is refused
| Refusal | Why |
|---|---|
| ZeroAmount | Amount must be greater than zero |
| UnknownCategory | Unknown spend category |
| Frozen | This wallet is frozen |
| CategoryNotAllowed | This wallet may not pay for that category |
| OverPerTxLimit | Amount is over the wallet's per-payment limit |
| OverDailyLimit | Amount would take the wallet over its daily limit |
| InsufficientBalance | The shared balance does not cover this amount |
| Overflow | Arithmetic 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