Full lesson
agentpay
Programmable wallets and payment rails for AI agents on Solana. Stripe for AI agents.
What it does
From the project README:
[](https://explorer.solana.com/address/3iJbMYgjMCFVkvHQSoeAb9EiTbcXyFqDxh88n4b7BP2s?cluster=devnet) [](https://github.com/coinbase/x402) [](https://modelcontextprotocol.io) [](LICENSE) [](https://www.anchor-lang.com/)
- Original
- 0xCaptain888/agentpay
- SuperStack fork
- Blockchains/agentpay @
e50e4ec - Stars
- 0
- Last push (original)
- 2026-05-04
- Languages
- TypeScript, Python, Rust, Shell, JavaScript, Dockerfile
- Detected stack
- AnchorNext.jssolana-pyweb3.js
- Categories
- AI & AgentsDeFi
- Licence
- MIT
Architecture
82 source files. By extension: .py ×34, .ts ×27, .tsx ×9, .rs ×9, .js ×3.
| Top-level directory | Source files |
|---|---|
apps | 47 |
packages | 19 |
programs | 11 |
scripts | 5 |
On-chain programs: programs/agent-vault/programs/agent-vault
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/agentpay/. 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/agent-vault/programs/agent-vault/src/instructions/withdraw_with_policy.rs L145–168 @ e50e4ec · MIT · original let new_today = spent_today .checked_add(amount).ok_or(VaultError::Overflow)?; require!(new_today <= max_per_day, VaultError::ExceedsDailyLimit); // ---- Phase 2: CPI with fee split ---- let bump_arr = [bump]; let seeds: &[&[u8]] = &[b"vault", agent_key.as_ref(), &bump_arr]; let signer_seeds = &[seeds]; // Calculate fee (fee_bps = 30 means 0.3%) let fee_amount: u64 = if fee_bps > 0 { (amount as u128) .checked_mul(fee_bps as u128).ok_or(VaultError::Overflow)? .checked_div(10_000).ok_or(VaultError::Overflow)? as u64 } else { 0 }; let net_amount = amount.checked_sub(fee_amount).ok_or(VaultError::Overflow)?; // Main transfer: vault → recipient (net_amount) token::transfer( CpiContext::new_with_signer( ctx.accounts.token_program.to_account_info(), Transfer {- Line 146
.checked_add(amount).ok_or(VaultError::Overflow)?;: Uses checked arithmetic so overflow fails instead of wrapping. - Line 147
require!(new_today <= max_per_day, VaultError::ExceedsDailyLimit);: An explicit validation that aborts the instruction with an error. - Line 150
let bump_arr = [bump];: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 152
let signer_seeds = &[seeds];: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match. - Line 165
token::transfer(: An SPL token transfer through the Token Program. - Line 166
CpiContext::new_with_signer(: Makes a CPI signed by a PDA. The signer seeds prove the program controls that address.
programs/agent-vault/programs/agent-vault/src/instructions/emergency_withdraw.rs L37–60 @ e50e4ec · MIT · original let signer_seeds = &[seeds]; token::transfer( CpiContext::new_with_signer( ctx.accounts.token_program.to_account_info(), Transfer { from: ctx.accounts.vault_ata.to_account_info(), to: ctx.accounts.owner_ata.to_account_info(), authority: ctx.accounts.vault.to_account_info(), }, signer_seeds, ), amount, )?; emit!(EmergencyWithdrawEvent { vault: ctx.accounts.vault.key(), owner: ctx.accounts.owner.key(), amount, ts: Clock::get()?.unix_timestamp, }); Ok(())}- Line 37
let signer_seeds = &[seeds];: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match. - Line 39
token::transfer(: An SPL token transfer through the Token Program. - Line 40
CpiContext::new_with_signer(: Makes a CPI signed by a PDA. The signer seeds prove the program controls that address. - Line 52
emit!(EmergencyWithdrawEvent {: Emits an Anchor event that clients can parse from the logs. - Line 56
ts: Clock::get()?.unix_timestamp,: Reads on-chain time from the Clock sysvar.
programs/agent-vault/programs/agent-vault/src/instructions/update_policy.rs L1–21 @ e50e4ec · MIT · originaluse anchor_lang::prelude::*;use crate::state::*;use crate::errors::VaultError; #[derive(Accounts)]pub struct UpdatePolicy<'info> { pub owner: Signer<'info>, #[account( mut, seeds = [b"vault", vault.authority.as_ref()], bump = vault.bump, has_one = owner @ VaultError::Unauthorized, )] pub vault: Account<'info, AgentVault>,} pub fn handler(ctx: Context<UpdatePolicy>, new_policy: SpendingPolicy) -> Result<()> { require!(new_policy.allowlist.len() <= 16, VaultError::AllowlistFull); ctx.accounts.vault.policy = new_policy; Ok(())}- Line 7
pub owner: Signer<'info>,: Requires this account to have signed the transaction. - Line 10
seeds = [b"vault", vault.authority.as_ref()],: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match. - Line 11
bump = vault.bump,: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 12
has_one = owner @ VaultError::Unauthorized,: Checks that a stored pubkey field matches the passed account. - Line 18
require!(new_policy.allowlist.len() <= 16, VaultError::AllowlistFull);: An explicit validation that aborts the instruction with an error.
programs/agent-vault/programs/agent-vault/src/instructions/initialize_fee_collector.rs L1–24 @ e50e4ec · MIT · originaluse anchor_lang::prelude::*;use anchor_spl::token::{Token, TokenAccount};use anchor_spl::associated_token::AssociatedToken;use anchor_spl::token::Mint;use crate::state::FeeCollector; #[derive(Accounts)]pub struct InitializeFeeCollector<'info> { #[account(mut)] pub payer: Signer<'info>, /// Fee collector authority (protocol team controls this) /// CHECK: Only storing pubkey, no type validation needed pub fee_authority: UncheckedAccount<'info>, pub mint: Account<'info, Mint>, #[account( init, payer = payer, space = FeeCollector::LEN, seeds = [FeeCollector::SEEDS], bump )]- Line 10
pub payer: Signer<'info>,: Requires this account to have signed the transaction. - Line 19
init,: Creates and pays for a new account. Space and payer must be specified. - Line 22
seeds = [FeeCollector::SEEDS],: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match. - Line 23
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 |
|---|---|---|
apps/dashboard | npm run dev | next dev |
apps/dashboard | npm run start | next start |
apps/dashboard | npm run build | next build |
apps/dashboard | npm run lint | next lint |
apps/example-api | npm run dev | npx tsx server.ts |
apps/example-api | npm run start | npx tsx server.ts |
apps/data-sink | npm run dev | tsx src/index.ts |
apps/data-sink | npm run start | tsx src/index.ts |
apps/agentpay-mcp | npm run dev | tsx src/index.ts |
apps/agentpay-mcp | npm run start | node dist/index.js |
apps/agentpay-mcp | npm run build | tsc |
programs/agent-vault | npm run test | anchor test |
packages/sdk-ts | npm run dev | tsup src/index.ts --format cjs,esm --dts --watch |
packages/sdk-ts | npm run build | tsup src/index.ts --format cjs,esm --dts |
packages/sdk-ts | npm run lint | tsc --noEmit |
programs/agent-vault | anchor build | compile programs and generate IDLs |
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