Full lesson
agentguard-protocol
Programmable spending firewall for autonomous agents on Solana.
What it does
From the project README:
AgentGuard Protocol is a Solana-native spending firewall for AI agents. Owners fund a policy vault, define merchant allowlists and token limits, and let an autonomous agent pay only inside those on-chain rules.
- Original
- davidweb3-ctrl/agentguard-protocol
- SuperStack fork
- Blockchains/agentguard-protocol @
e2a0354 - Stars
- 0
- Last push (original)
- 2026-06-05
- Languages
- TypeScript, JavaScript, Rust
- Detected stack
- AnchorNext.jsweb3.js
- Categories
- AI & AgentsDeFi
- Licence
- Apache-2.0
Architecture
15 source files. By extension: .ts ×12, .tsx ×2, .rs ×1.
| Top-level directory | Source files |
|---|---|
services | 6 |
apps | 4 |
tests | 2 |
migrations | 1 |
programs | 1 |
packages | 1 |
On-chain programs: programs/agentguard-protocol
Dapp: devnet deploy pending
⏳ Devnet deploy pending — goes live when the devnet wallet is topped up. This fork's own dapp is not deployed yet, so there is no program address or transaction to show. It is queued in dapp-queue.txt; once devnet SOL is available it is deployed, exercised with real devnet transactions, and this section switches to the live dapp at /dapps/agentguard-protocol/. Until then, the lesson and step-by-step guide below are complete, and you can run it locally with the commands below.
Key code, explained
Excerpts chosen automatically where the code uses the most Solana concepts, pinned to the fork's commit.
programs/agentguard-protocol/src/lib.rs L265–288 @ e2a0354 · Apache-2.0 · original #[derive(Accounts)]#[instruction(merchant: Pubkey)]pub struct AddMerchant<'info> { #[account(mut)] pub owner: Signer<'info>, #[account(has_one = owner @ ErrorCode::UnauthorizedOwner)] pub agent_profile: Account<'info, AgentProfile>, #[account( init, payer = owner, space = 8 + MerchantPolicy::INIT_SPACE, seeds = [b"merchant", agent_profile.key().as_ref(), merchant.as_ref()], bump )] pub merchant_policy: Account<'info, MerchantPolicy>, pub system_program: Program<'info, System>,} #[derive(Accounts)]#[instruction(amount: u64, request_hash: [u8; 32])]pub struct AgentPay<'info> { #[account(mut)] pub agent_authority: Signer<'info>,- Line 270
pub owner: Signer<'info>,: Requires this account to have signed the transaction. - Line 271
#[account(has_one = owner @ ErrorCode::UnauthorizedOwner)]: Checks that a stored pubkey field matches the passed account. - Line 274
init,: Creates and pays for a new account. Space and payer must be specified. - Line 277
seeds = [b"merchant", agent_profile.key().as_ref(), merchant.as_ref()],: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match. - Line 278
bump: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve.
How to run, build and test
These commands come from the repo's own manifests (package.json scripts, Anchor.toml, Cargo, go.mod, Makefile). Check the README for prerequisites and environment variables.
| Directory | Command | Runs |
|---|---|---|
. | npm run build | anchor build |
. | npm run test | anchor test |
. | npm run lint | prettier "**/*.{js,ts,tsx,json,md}" --check |
services/x402-demo-api | npm run dev | pnpm --filter @agentguard/sdk build && tsx src/server.ts |
apps/web | npm run dev | next dev |
apps/web | npm run start | next start |
apps/web | npm run build | next build |
apps/web | npm run lint | next lint |
packages/sdk | npm run build | tsc -p tsconfig.json |
. | anchor build | compile programs and generate IDLs |
. | anchor test | local validator + test suite |
. | anchor run test | pnpm exec ts-mocha -p ./tsconfig.json -t 1000000 \ |
. | cargo build | Rust workspace build |
. | cargo test | Rust tests |
What you could build from it
- Fork the SuperStack copy and extend it within the AI & Agents gaps listed on the idea page.
- Learn the pattern first: AI agents on Solana
- Learn the pattern first: Building and sending transactions from a client