Sol.College

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 directorySource files
src90
(root)5
programs1
tests1

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.

justin212407/TheZapCoin · 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
  1. Line 85 loan.creation_time = Clock::get()?.unix_timestamp;: Reads on-chain time from the Clock sysvar.
  2. 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.
  3. 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.
  4. Line 102 require!(loan.status == LoanStatus::Active, ErrorCode::LoanNotActive);: An explicit validation that aborts the instruction with an error.
  5. Line 105 let remaining_amount = loan.amount.checked_sub(loan.repaid_amount): Uses checked arithmetic so overflow fails instead of wrapping.
justin212407/TheZapCoin · src/lib/solana/index.ts L1–23 @ 022cae3 · MIT · original
import {  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';
  1. Line 7 sendAndConfirmTransaction,: Submits the signed transaction to the cluster.
  2. 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.

DirectoryCommandRuns
.npm run devvite
.npm run buildvite build
.npm run linteslint .
.anchor buildcompile programs and generate IDLs
.anchor testlocal validator + test suite
.anchor run testyarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts

What you could build from it