Full lesson
WorkChain
Payment protocol for AI agents on Solana - condition-based escrow with AI verification
What it does
From the project README:
[](https://opensource.org/licenses/MIT) [](https://explorer.solana.com/) [](https://www.anchor-lang.com/) []() [](https://workchain-protocol.vercel.app) [](https://workchain-production.up.railway.app/health)
- Original
- adityachotaliya9299-jpg/WorkChain
- SuperStack fork
- Blockchains/WorkChain @
04e8902 - Stars
- 1
- Last push (original)
- 2026-06-30
- Languages
- TypeScript, Rust, CSS, JavaScript
- Detected stack
- AnchorNext.jsweb3.js
- Categories
- AI & AgentsDeFi
- Licence
- MIT
- Homepage
- https://work-chain-flame.vercel.app
Architecture
51 source files. By extension: .ts ×23, .tsx ×17, .rs ×10, .js ×1.
| Top-level directory | Source files |
|---|---|
frontend | 20 |
verifier | 14 |
programs | 10 |
tests | 2 |
docs | 1 |
migrations | 1 |
sdk | 1 |
subgraph | 1 |
On-chain programs: programs/workchain
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/workchain/. 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/workchain/src/instructions/dispute_work_order.rs L25–48 @ 04e8902 · MIT · original emit!(WorkOrderDisputed { work_order: ctx.accounts.work_order.key(), client: ctx.accounts.client.key(), disputed_at: clock.unix_timestamp, }); Ok(())} #[derive(Accounts)]pub struct DisputeWorkOrder<'info> { pub client: Signer<'info>, #[account( mut, seeds = [ b"work_order", client.key().as_ref(), work_order.condition_hash.as_ref() ], bump = work_order.bump, has_one = client @ WorkChainError::UnauthorizedClient, )]- Line 26
emit!(WorkOrderDisputed {: Emits an Anchor event that clients can parse from the logs. - Line 29
disputed_at: clock.unix_timestamp,: Reads on-chain time from the Clock sysvar. - Line 37
pub client: Signer<'info>,: Requires this account to have signed the transaction. - Line 41
seeds = [: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match. - Line 46
bump = work_order.bump,: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 47
has_one = client @ WorkChainError::UnauthorizedClient,: Checks that a stored pubkey field matches the passed account.
programs/workchain/src/instructions/register_verifier.rs L25–48 @ 04e8902 · MIT · original record.verifier = ctx.accounts.verifier.key(); record.name = name; record.stake = VerifierRecord::MIN_STAKE; record.jobs_completed = 0; record.jobs_disputed = 0; record.registered_at = clock.unix_timestamp; record.is_active = true; record.bump = ctx.bumps.verifier_record; emit!(VerifierRegistered { verifier: ctx.accounts.verifier.key(), registered_at: clock.unix_timestamp, }); Ok(())} #[derive(Accounts)]pub struct RegisterVerifier<'info> { #[account(mut)] pub verifier: Signer<'info>, #[account( init,- Line 27
record.stake = VerifierRecord::MIN_STAKE;: Touches staking state: the amount locked and when it was locked. - Line 30
record.registered_at = clock.unix_timestamp;: Reads on-chain time from the Clock sysvar. - Line 32
record.bump = ctx.bumps.verifier_record;: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 34
emit!(VerifierRegistered {: Emits an Anchor event that clients can parse from the logs. - Line 45
pub verifier: Signer<'info>,: Requires this account to have signed the transaction. - Line 48
init,: Creates and pays for a new account. Space and payer must be specified.
programs/workchain/src/instructions/complete_work_order.rs L85–108 @ 04e8902 · MIT · original completed_at: clock.unix_timestamp, proof, }); Ok(())} #[derive(Accounts)]pub struct CompleteWorkOrder<'info> { pub verifier: Signer<'info>, #[account( mut, seeds = [ b"work_order", work_order.client.as_ref(), work_order.condition_hash.as_ref() ], bump = work_order.bump, has_one = verifier @ WorkChainError::UnauthorizedVerifier, )] pub work_order: Account<'info, WorkOrder>, #[account(- Line 85
completed_at: clock.unix_timestamp,: Reads on-chain time from the Clock sysvar. - Line 94
pub verifier: Signer<'info>,: Requires this account to have signed the transaction. - Line 98
seeds = [: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match. - Line 103
bump = work_order.bump,: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 104
has_one = verifier @ WorkChainError::UnauthorizedVerifier,: Checks that a stored pubkey field matches the passed account.
programs/workchain/src/instructions/create_work_order.rs L73–96 @ 04e8902 · MIT · original recipient: params.recipient, verifier: params.verifier, payment_amount: params.payment_amount, protocol_fee, deadline: params.deadline, created_at: clock.unix_timestamp, }); Ok(())} #[derive(Accounts)]#[instruction(params: CreateWorkOrderParams)]pub struct CreateWorkOrder<'info> { #[account(mut)] pub client: Signer<'info>, #[account( init, payer = client, space = WorkOrder::LEN, seeds = [b"work_order", client.key().as_ref(), params.condition_hash.as_ref()], bump )]- Line 78
created_at: clock.unix_timestamp,: Reads on-chain time from the Clock sysvar. - Line 88
pub client: Signer<'info>,: Requires this account to have signed the transaction. - Line 91
init,: Creates and pays for a new account. Space and payer must be specified. - Line 94
seeds = [b"work_order", client.key().as_ref(), params.condition_hash.as_ref()],: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match. - Line 95
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 lint | prettier */*.js "*/**/*{.js,.ts}" --check |
sdk | npm run dev | tsc --watch |
sdk | npm run build | tsc |
frontend | npm run dev | next dev |
frontend | npm run start | next start |
frontend | npm run build | next build |
frontend | npm run lint | next lint |
verifier | npm run dev | nodemon --exec ts-node src/index.ts |
verifier | npm run start | node dist/index.js |
verifier | npm run build | tsc && mkdir -p dist/idl && cp src/idl/workchain.json dist/idl/workchain.json |
verifier | npm run test | ts-mocha -p ./tsconfig.json -t 10000 src/tests/**/*.test.ts |
. | anchor build | compile programs and generate IDLs |
. | anchor test | local validator + test suite |
. | anchor run test | yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts |
. | 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
- Learn the pattern first: Blinks and Solana Actions