Full lesson
TheZapCoin
Zapcoin is a revolutionary DeFi platform built on the Solana blockchain that connects renewable energy production with financial services.
What it does
From the project README:
Zapcoin is a revolutionary DeFi platform built on the Solana blockchain that connects renewable energy production with financial services. The platform allows users to:
- Original
- justin212407/TheZapCoin
- SuperStack fork
- Blockchains/TheZapCoin @
022cae3 - Stars
- 0
- Last push (original)
- 2025-05-16
- Languages
- TypeScript, Rust, CSS, JavaScript, HTML
- Detected stack
- Anchorweb3.js
- Categories
- DeFi
- Licence
- MIT
- Homepage
- https://thezapcoin-official.netlify.app/
Architecture
97 source files. By extension: .tsx ×78, .ts ×15, .js ×3, .rs ×1.
| Top-level directory | Source files |
|---|---|
src | 90 |
(root) | 5 |
programs | 1 |
tests | 1 |
On-chain programs: programs/zapcoin
Dapp: deploying
This fork is queued for its own live dapp on Sol.College, with a Devnet/Mainnet switch. It appears here, at /dapps/thezapcoin/, once it is deployed and checked on devnet. Until then, 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/zapcoin/src/lib.rs L85–108 @ 022cae3 · MIT · original loan.creation_time = Clock::get()?.unix_timestamp; loan.repaid_amount = 0; loan.status = LoanStatus::Active; loan.bump = *ctx.bumps.get("loan").unwrap(); msg!("Loan created: {} tokens, {} days term", amount, term_days); Ok(()) } // Repay a loan with energy tokens pub fn repay_loan_with_energy( ctx: Context<RepayLoanWithEnergy>, amount: u64, ) -> Result<()> { let loan = &mut ctx.accounts.loan; // Ensure the loan is active require!(loan.status == LoanStatus::Active, ErrorCode::LoanNotActive); // Calculate the remaining amount to repay let remaining_amount = loan.amount.checked_sub(loan.repaid_amount) .ok_or(ErrorCode::ArithmeticOverflow)?; // Ensure the repayment amount is not more than what's remaining- Line 85
loan.creation_time = Clock::get()?.unix_timestamp;: Reads on-chain time from the Clock sysvar. - Line 88
loan.bump = *ctx.bumps.get("loan").unwrap();: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 90
msg!("Loan created: {} tokens, {} days term", amount, term_days);: Logs to the program log, which is visible in explorers and the test output. - Line 102
require!(loan.status == LoanStatus::Active, ErrorCode::LoanNotActive);: An explicit validation that aborts the instruction with an error. - Line 105
let remaining_amount = loan.amount.checked_sub(loan.repaid_amount): Uses checked arithmetic so overflow fails instead of wrapping.
src/lib/solana/index.ts L1–23 @ 022cae3 · MIT · originalimport { Connection, PublicKey, Transaction, SystemProgram, Keypair, sendAndConfirmTransaction, ConfirmOptions, LAMPORTS_PER_SOL} from '@solana/web3.js';import { TOKEN_PROGRAM_ID, getAssociatedTokenAddress, createAssociatedTokenAccountInstruction, getAccount, createMint, getMint, mintTo, transfer, createTransferInstruction} from '@solana/spl-token';import { Program, AnchorProvider, web3, BN, Idl, setProvider } from '@project-serum/anchor';import idl from './zapcoin.json';- Line 7
sendAndConfirmTransaction,: Submits the signed transaction to the cluster. - Line 20
createTransferInstruction: An SPL token transfer through the Token Program.
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 | vite |
. | npm run build | vite build |
. | npm run lint | eslint . |
. | 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 |
What you could build from it
- Fork the SuperStack copy and extend it within the DeFi gaps listed on the idea page.
- Learn the pattern first: Program Derived Addresses (PDAs)
- Learn the pattern first: Cross-Program Invocations (CPIs)
- Learn the pattern first: SPL Tokens: mints, accounts and transfers