Full lesson
ChipCasher
- Original
- asimbugra/ChipCasher
- SuperStack fork
- Blockchains/ChipCasher @
b322aef - Stars
- 0
- Last push (original)
- 2025-02-27
- Languages
- TypeScript, CSS, JavaScript
- Detected stack
- Next.jsSolana Payweb3.js
- Categories
- Other
- Licence
- MIT
Architecture
27 source files. By extension: .tsx ×17, .js ×5, .ts ×5.
| Top-level directory | Source files |
|---|---|
pages | 10 |
components | 9 |
(root) | 5 |
lib | 3 |
Dapp: deploying
This fork is queued for its own live dapp on Sol.College, with a Devnet/Mainnet switch. It appears here, at /dapps/chipcasher/, 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.
pages/checkout.tsx L1–24 @ b322aef · MIT · originalimport { useConnection, useWallet } from "@solana/wallet-adapter-react";import { WalletMultiButton } from "@solana/wallet-adapter-react-ui";import { Keypair, Transaction } from "@solana/web3.js";import { findReference, FindReferenceError } from "@solana/pay";import { useRouter } from "next/router";import { useEffect, useMemo, useState } from "react";import dynamic from "next/dynamic";import BackLink from "../components/BackLink";import Loading from "../components/Loading";import { MakeTransactionInputData, MakeTransactionOutputData } from "./api/makeTransaction";import { WalletSendTransactionError } from "@solana/wallet-adapter-base"; // Dynamic import to prevent SSR issuesconst WalletMultiButtonDynamic = dynamic( () => import("@solana/wallet-adapter-react-ui").then((mod) => mod.WalletMultiButton), { ssr: false }); export default function Checkout() { const router = useRouter(); const { connection } = useConnection(); const { publicKey, sendTransaction } = useWallet(); // State to hold API response fields- Line 4
import { findReference, FindReferenceError } from "@solana/pay";: Finds or validates the on-chain payment by its reference key. - Line 22
const { publicKey, sendTransaction } = useWallet();: Submits the signed transaction to the cluster.
pages/api/makeTransaction.ts L85–108 @ b322aef · MIT · original res.status(500).json({ error: "Error fetching associated token addresses" }); return; } // Fetch recent blockhash for transaction let blockhash: string; try { ({ blockhash } = await connection.getLatestBlockhash('finalized')); console.log('Fetched recent blockhash:', blockhash); } catch (error) { console.error('Error fetching recent blockhash:', error); res.status(500).json({ error: "Error fetching recent blockhash" }); return; } const transaction = new Transaction({ recentBlockhash: blockhash, feePayer: buyerPublicKey, }); // Create the transfer instruction try { const transferInstruction = createTransferCheckedInstruction( buyerUsdcAddress,- Line 92
({ blockhash } = await connection.getLatestBlockhash('finalized'));: Fetches a recent blockhash. Transactions expire if it gets too old. - Line 107
const transferInstruction = createTransferCheckedInstruction(: A checked token transfer, which also verifies the mint and decimals.
pages/shop/checkout.tsx L1–24 @ b322aef · MIT · originalimport { createQR, encodeURL, TransactionRequestURLFields, findReference, validateTransfer, FindReferenceError, ValidateTransferError } from "@solana/pay";import { WalletAdapterNetwork } from "@solana/wallet-adapter-base";import { clusterApiUrl, Connection, Keypair } from "@solana/web3.js";import { useRouter } from "next/router";import { useEffect, useMemo, useRef } from "react";import BackLink from "../../components/BackLink";import PageHeading from "../../components/PageHeading";import { shopAddress, usdcAddress } from "../../lib/addresses";import calculatePrice from "../../lib/calculatePrice"; export default function Checkout() { const router = useRouter(); // ref to a div where we'll show the QR code const qrRef = useRef<HTMLDivElement>(null); const amount = useMemo(() => calculatePrice(router.query), [router.query]); // Unique address that we can listen for payments to const reference = useMemo(() => Keypair.generate().publicKey, []); // Read the URL query (which includes our chosen products) const searchParams = useMemo(() => { const params = new URLSearchParams({ reference: reference.toString() });- Line 1
import { createQR, encodeURL, TransactionRequestURLFields, findReference, validateTransfer: Encodes a Solana Pay request URL. - Line 1
import { createQR, encodeURL, TransactionRequestURLFields, findReference, validateTransfer: Finds or validates the on-chain payment by its reference key.
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 | next dev |
. | npm run start | next start |
. | npm run build | next build |
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)