Sol.College

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 directorySource files
apps47
packages19
programs11
scripts5

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.

0xCaptain888/agentpay · 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 {
  1. Line 146 .checked_add(amount).ok_or(VaultError::Overflow)?;: Uses checked arithmetic so overflow fails instead of wrapping.
  2. Line 147 require!(new_today <= max_per_day, VaultError::ExceedsDailyLimit);: An explicit validation that aborts the instruction with an error.
  3. Line 150 let bump_arr = [bump];: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve.
  4. Line 152 let signer_seeds = &[seeds];: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match.
  5. Line 165 token::transfer(: An SPL token transfer through the Token Program.
  6. Line 166 CpiContext::new_with_signer(: Makes a CPI signed by a PDA. The signer seeds prove the program controls that address.
0xCaptain888/agentpay · 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(())}
  1. Line 37 let signer_seeds = &[seeds];: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match.
  2. Line 39 token::transfer(: An SPL token transfer through the Token Program.
  3. Line 40 CpiContext::new_with_signer(: Makes a CPI signed by a PDA. The signer seeds prove the program controls that address.
  4. Line 52 emit!(EmergencyWithdrawEvent {: Emits an Anchor event that clients can parse from the logs.
  5. Line 56 ts: Clock::get()?.unix_timestamp,: Reads on-chain time from the Clock sysvar.
0xCaptain888/agentpay · programs/agent-vault/programs/agent-vault/src/instructions/update_policy.rs L1–21 @ e50e4ec · MIT · original
use 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(())}
  1. Line 7 pub owner: Signer<'info>,: Requires this account to have signed the transaction.
  2. 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.
  3. Line 11 bump = vault.bump,: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve.
  4. Line 12 has_one = owner @ VaultError::Unauthorized,: Checks that a stored pubkey field matches the passed account.
  5. Line 18 require!(new_policy.allowlist.len() <= 16, VaultError::AllowlistFull);: An explicit validation that aborts the instruction with an error.
0xCaptain888/agentpay · programs/agent-vault/programs/agent-vault/src/instructions/initialize_fee_collector.rs L1–24 @ e50e4ec · MIT · original
use 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    )]
  1. Line 10 pub payer: Signer<'info>,: Requires this account to have signed the transaction.
  2. Line 19 init,: Creates and pays for a new account. Space and payer must be specified.
  3. Line 22 seeds = [FeeCollector::SEEDS],: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match.
  4. 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.

DirectoryCommandRuns
apps/dashboardnpm run devnext dev
apps/dashboardnpm run startnext start
apps/dashboardnpm run buildnext build
apps/dashboardnpm run lintnext lint
apps/example-apinpm run devnpx tsx server.ts
apps/example-apinpm run startnpx tsx server.ts
apps/data-sinknpm run devtsx src/index.ts
apps/data-sinknpm run starttsx src/index.ts
apps/agentpay-mcpnpm run devtsx src/index.ts
apps/agentpay-mcpnpm run startnode dist/index.js
apps/agentpay-mcpnpm run buildtsc
programs/agent-vaultnpm run testanchor test
packages/sdk-tsnpm run devtsup src/index.ts --format cjs,esm --dts --watch
packages/sdk-tsnpm run buildtsup src/index.ts --format cjs,esm --dts
packages/sdk-tsnpm run linttsc --noEmit
programs/agent-vaultanchor buildcompile programs and generate IDLs

What you could build from it

Used in lessons