Start
How it works
The life of one guarded transaction, step by step.
The shape of a guarded transaction
[ Begin, ...the instructions of any app..., End ]
One signature covers all of it. The wallet builds the transaction, adds Begin and End, and you sign once.
1. Begin: the snapshot
Begin receives the accounts to watch (your wallet first, then up to nine others, usually token accounts). For each one it stores what End will need: lamports, the program that owns the account, and for token accounts the amount, the owner, the delegate, the delegated amount and the close authority. It stores them in your guard account, a PDA derived from your address, and arms it with the current slot.
2. The app's instructions
Anything. Swaps, claims, mints, a dapp you do not trust. They run as usual.
3. End: the verdict
End must be the last instruction and must find its own Begin earlier in the same transaction (it reads the Instructions sysvar), so a stale snapshot can never be reused and nothing can be appended after the check. Then, for every watched account, in this order:
| # | Rule | Fails with |
|---|---|---|
| 1 | It is still there (a token account has not been closed) | AccountClosed |
| 2 | Still owned by the same program (a System Assign would change it) | ProgramChanged |
| 3 | SOL moved by at least what you accepted, or did not go down if you said nothing | CheckFailed / WatchFailed |
| 4 | Token amount, same rule | CheckFailed / WatchFailed |
| 5 | The owner of the token account is unchanged | AuthorityChanged |
| 6 | No new or bigger delegate, unless a check caps it | DelegateNotDeclared |
| 7 | No close authority appears or changes | CloseAuthority |
The error also carries the number of the watched account that broke the rule.
Why a failed End undoes everything
A Solana transaction is all-or-nothing. If End returns an error, every earlier instruction is rolled back. You pay the base fee and nothing else.
What it costs
About 6,735 compute units for a guard around three accounts, a small fraction of the 200,000 a transaction gets by default. The guard account holds about 0.0146 SOL of rent, which Close gives back.