Full lesson
agent-economy-wallet
An Agentic Wallet for an Agentic Marketplace
What it does
From the project README:
Agent-to-Agent Marketplace SDK on Solana — discover, evaluate, and pay for services autonomously.
- Original
- xavierScript/agent-economy-wallet
- SuperStack fork
- Blockchains/agent-economy-wallet @
e2b7534 - Stars
- 0
- Last push (original)
- 2026-05-11
- Languages
- TypeScript, CSS, JavaScript, Rust, Makefile, Dockerfile
- Detected stack
- AnchorNext.jsweb3.js
- Categories
- AI & AgentsWallets & Identity
- Licence
- MIT
- Homepage
- https://agent-economy-wallet-explorer.vercel.app
Architecture
128 source files. By extension: .ts ×93, .tsx ×27, .rs ×8.
| Top-level directory | Source files |
|---|---|
packages | 118 |
programs | 10 |
On-chain programs: programs/onchain-program/programs/onchain-program
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/agent-economy-wallet/. 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/onchain-program/programs/onchain-program/src/instructions/streaming.rs L13–36 @ e2b7534 · MIT · original/// Create a StreamSession PDA on L1 before delegation.pub fn initialize_session( ctx: Context<InitializeSession>, session_id: [u8; 16], rate_per_tick: u64, interval_ms: u64,) -> Result<()> { require!(interval_ms >= 500, StreamError::IntervalTooFast); require!(rate_per_tick > 0, StreamError::InvalidRate); let session = &mut ctx.accounts.session; session.session_id = session_id; session.buyer = ctx.accounts.payer.key(); session.merchant = ctx.accounts.merchant.key(); session.rate_per_tick = rate_per_tick; session.interval_ms = interval_ms; session.tick_count = 0; session.total_paid = 0; session.status = SessionStatus::Active; session.started_at = Clock::get()?.unix_timestamp; session.bump = ctx.bumps.session; msg!( "Stream session initialized: buyer={}, merchant={}, rate={}/{}ms",- Line 20
require!(interval_ms >= 500, StreamError::IntervalTooFast);: An explicit validation that aborts the instruction with an error. - Line 32
session.started_at = Clock::get()?.unix_timestamp;: Reads on-chain time from the Clock sysvar. - Line 33
session.bump = ctx.bumps.session;: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 35
msg!(: Logs to the program log, which is visible in explorers and the test output.
programs/onchain-program/programs/onchain-program/src/instructions/reputation.rs L13–36 @ e2b7534 · MIT · original account.total_payments = 0; account.total_volume_lamports = 0; account.unique_buyers = 0; account.last_payment_ts = 0; account.bump = ctx.bumps.merchant_account; msg!( "Merchant reputation initialized: {}", ctx.accounts.merchant.key() ); Ok(())} /// Record a payment to a merchant./// Called by the buyer after a successful x402 payment./// Updates total payment count, volume, and timestamp.////// The unique_buyers counter is incremented every 5 payments as/// a simple heuristic — a production version would track exact/// unique buyers via a bitmap or separate PDA.pub fn record_payment(ctx: Context<RecordPayment>, amount: u64) -> Result<()> { let account = &mut ctx.accounts.merchant_account; account.total_payments = account.total_payments.checked_add(1).unwrap();- Line 17
account.bump = ctx.bumps.merchant_account;: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 19
msg!(: Logs to the program log, which is visible in explorers and the test output. - Line 27
/// Called by the buyer after a successful x402 payment.: Uses x402, an HTTP 402 pattern where an agent pays per request with an on-chain payment. - Line 36
account.total_payments = account.total_payments.checked_add(1).unwrap();: Uses checked arithmetic so overflow fails instead of wrapping.
packages/mcp-server/src/tools/index.ts L13–36 @ e2b7534 · MIT · originalimport { registerGetBalanceTool } from "./wallet/get-balance.js";// close-wallet is intentionally NOT registered here.// Wallet closure is a destructive, irreversible operation and must only be// initiated by a human via the CLI. Agents must never be able to close wallets.import { registerGetAuditLogsTool } from "./wallet/get-audit-logs.js";import { registerGetStatusTool } from "./wallet/get-status.js";import { registerGetPolicyTool } from "./wallet/get-policy.js";import { registerSendSolTool } from "./transfers/send-sol.js";import { registerSendTokenTool } from "./transfers/send-token.js";import { registerWriteMemoTool } from "./transfers/write-memo.js";import { registerMintTokenTool } from "./tokens/mint-token.js"; // payments/import { registerPayX402Tool } from "./payments/pay-x402.js";import { registerProbeX402Tool } from "./payments/probe-x402.js"; // merchant/import { registerFetchPricesTool } from "./merchant/fetch-prices.js";import { registerAnalyzeTokenSecurityTool } from "./merchant/analyze-token-security.js";import { registerMonitorNetworkOracleTool } from "./merchant/monitor-network-oracle.js"; // discovery/ — buyer agent tools for finding and evaluating merchantsimport { registerDiscoverRegistryTool } from "./discovery/discover-registry.js";import { registerReadManifestTool } from "./discovery/read-manifest.js";- Line 23
import { registerMintTokenTool } from "./tokens/mint-token.js";: Mints new tokens. The mint authority must sign. - Line 26
import { registerPayX402Tool } from "./payments/pay-x402.js";: Uses x402, an HTTP 402 pattern where an agent pays per request with an on-chain payment.
packages/mcp-server/src/tools/payments/pay-x402.ts L85–108 @ e2b7534 · MIT · original fetchOptions.body = body; } // Sign callback — signs via WalletService which enforces policies const signTx = async (tx: Transaction): Promise<Transaction> => { // We need to sign the transaction with the wallet's keypair. // The WalletService.signAndSendTransaction sends immediately, but // for x402 we only need a signature (the facilitator submits). // We unlock the keypair through KeyManager and sign locally. const keypair = keyManager.unlockWallet(wallet_id); // Policy check via a lightweight limits check const violation = services.policyEngine.checkLimits(wallet_id, 0); if (violation) { throw new Error(`Policy violation: ${violation}`); } // Every Solana transaction needs a recent blockhash before it can be // signed. The x402 client builds the transaction without one (it has // no RPC access), so we must hydrate it here before calling partialSign. if (!tx.recentBlockhash) { const { blockhash } = await services.connection.getLatestBlockhash(); tx.recentBlockhash = blockhash; }- Line 92
// for x402 we only need a signature (the facilitator submits).: Uses x402, an HTTP 402 pattern where an agent pays per request with an on-chain payment. - Line 106
const { blockhash } = await services.connection.getLatestBlockhash();: Fetches a recent blockhash. Transactions expire if it gets too old.
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 dev | pnpm -r --parallel dev |
. | npm run start | pnpm build && pnpm server |
. | npm run build | pnpm --filter @agent-economy-wallet/core build && pnpm --filter @agent-economy-wallet/cli build && pnpm --filter @agent- |
. | npm run test | pnpm -r test |
. | npm run lint | pnpm -r lint |
programs/onchain-program | npm run lint | prettier */*.js "*/**/*{.js,.ts}" --check |
packages/cli | npm run dev | tsc --watch |
packages/cli | npm run start | node dist/index.js |
packages/cli | npm run build | tsc |
packages/mcp-server | npm run dev | tsc --watch |
packages/mcp-server | npm run start | node dist/index.js |
packages/mcp-server | npm run build | tsc |
packages/wallet-core | npm run dev | tsc --watch |
packages/wallet-core | npm run build | tsc |
packages/wallet-core | npm run test | vitest run |
packages/sdk | npm run dev | tsc --watch |
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