Full lesson
0ktopus
What it does
From the project README:
0KTOPUS transforms API subscriptions and digital access into tradeable NFTs on Solana. Instead of recurring subscriptions, users purchase access NFTs that:
- Original
- jackoske/0ktopus
- SuperStack fork
- Blockchains/0ktopus @
3ee9ffc - Stars
- 2
- Last push (original)
- 2025-10-28
- Languages
- TypeScript, Rust, JavaScript, CSS
- Detected stack
- AnchorNext.jsweb3.js
- Categories
- Other
- Licence
- Apache-2.0
Architecture
49 source files. By extension: .ts ×22, .tsx ×17, .rs ×7, .js ×3.
| Top-level directory | Source files |
|---|---|
capability-frontend | 28 |
capability-protocol | 13 |
integration-sdk | 4 |
demo-app | 2 |
access-backend | 2 |
On-chain programs: capability-protocol/programs/capability-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/0ktopus/. 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.
capability-protocol/programs/capability-protocol/src/lib.rs L73–96 @ 3ee9ffc · Apache-2.0 · original product.active = true; product.bump = ctx.bumps.product; msg!("Product registered: {}", product.name); Ok(()) } pub fn purchase_access<'info>( ctx: Context<'_, '_, '_, 'info, PurchaseAccess<'info>>, purchase_nonce: u64, ) -> Result<()> { let product = &ctx.accounts.product; let config = &ctx.accounts.config; let total_price = product.price_lamports; let platform_fee = (total_price as u128) .checked_mul(config.fee_bps as u128) .and_then(|v| v.checked_div(10000)) .and_then(|v| u64::try_from(v).ok()) .ok_or(CapabilityError::ArithmeticOverflow)?; // Transfer platform fee using CPI let cpi_context = anchor_lang::context::CpiContext::new( ctx.accounts.system_program.to_account_info(), anchor_lang::system_program::Transfer {- Line 74
product.bump = ctx.bumps.product;: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 75
msg!("Product registered: {}", product.name);: Logs to the program log, which is visible in explorers and the test output. - Line 88
.checked_mul(config.fee_bps as u128): Uses checked arithmetic so overflow fails instead of wrapping. - Line 94
let cpi_context = anchor_lang::context::CpiContext::new(: Makes a cross-program invocation into another program.
capability-frontend/app/components/sections/TransferSection.tsx L49–71 @ 3ee9ffc · Apache-2.0 · original const toAta = getAssociatedTokenAddressSync(nftMint, recipient); const transaction = new Transaction(); // Check if recipient ATA exists const toAccountInfo = await connection.getAccountInfo(toAta); if (!toAccountInfo) { transaction.add( createAssociatedTokenAccountInstruction( wallet.publicKey, toAta, recipient, nftMint ) ); } transaction.add( createTransferInstruction(fromAta, toAta, wallet.publicKey, 1) ); transaction.feePayer = wallet.publicKey; transaction.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;- Line 67
createTransferInstruction(fromAta, toAta, wallet.publicKey, 1): An SPL token transfer through the Token Program. - Line 71
transaction.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;: Fetches a recent blockhash. Transactions expire if it gets too old.
capability-protocol/programs/capability-protocol/src/state/access_state.rs L13–36 @ 3ee9ffc · Apache-2.0 · original impl AccessState { pub const LEN: usize = 8 + // discriminator 32 + // nft_mint 32 + // buyer 32 + // product 1 + 4 + // remaining_uses (Option<u32>) 1 + 8 + // expires_at (Option<i64>) 8 + // purchase_nonce 1; // bump pub fn is_valid(&self, clock: &Clock) -> bool { // Check if expired if let Some(expires_at) = self.expires_at { if clock.unix_timestamp > expires_at { return false; } } // Check if uses remaining if let Some(remaining) = self.remaining_uses { if remaining == 0 { return false; }- Line 22
1; // bump: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 27
if clock.unix_timestamp > expires_at {: Reads on-chain time from the Clock sysvar.
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 |
|---|---|---|
integration-sdk | npm run dev | tsup --watch |
integration-sdk | npm run build | tsup src/index.ts src/react/index.ts --format cjs,esm --dts |
integration-sdk | npm run test | vitest |
integration-sdk | npm run lint | eslint src/ |
demo-app/backend | npm run dev | tsx watch src/index.ts |
demo-app/backend | npm run start | node dist/index.js |
demo-app/backend | npm run build | tsc |
demo-app/backend | npm run test | vitest |
demo-app/backend | npm run lint | eslint src/ |
access-backend | npm run dev | tsx watch src/index.ts |
access-backend | npm run start | node dist/index.js |
access-backend | npm run build | tsc |
access-backend | npm run test | vitest |
access-backend | npm run lint | eslint src/ |
capability-frontend | npm run dev | next dev |
capability-frontend | npm run start | next start |
What you could build from it
- Fork the SuperStack copy and extend it within the Other gaps listed on the idea page.
- Learn the pattern first: Program Derived Addresses (PDAs)
- Learn the pattern first: Cross-Program Invocations (CPIs)