Full DApp Project — Web3

Raka's Shirt Shop's full dApp is smart contracts (RakaPoints ERC-20 and CoffeeEditionShirt ERC-721) as the trusted backend, a wallet to sign, a React + wagmi…

Seventeen lessons, seventeen pieces. In this lesson every piece from lessons 1 to 17 is put together into one project: Raka's Shirt Shop. The result is a full dApp, an app whose rules and important data live in smart contracts, used through the user's wallet, shown by a frontend, with big files on IPFS and the history summed up by an indexer. It feels like the shop's opening day. There is a till whose rules can't be changed (the contract), a member card in the customer's wallet (the wallet), the shop window (the frontend), the warehouse for catalogue photos (IPFS), the monthly summary book (the indexer), and a back office for things that must not be shown in the public book, such as delivery addresses (your own server).

Raka's Shirt Shop's architecture

Piece What it holds Tools
Smart contracts RakaPoints (ERC-20, 1 PTS per $1, 100 PTS = $5 off) and CoffeeEditionShirt (ERC-721, at most 100) Solidity, OpenZeppelin 5.6.1, Hardhat 3.19.0
Wallet the customer's key; signs redeem MetaMask or another EIP-6963 wallet
Frontend the "your PTS" page and the redeem button React, wagmi 3.7.7, viem 2.57.4
IPFS COFFEE's metadata and images, pointed at with ipfs:// kubo, a pinning service
Indexer PTS holder rankings, Transfer history, COFFEE owners a subgraph (The Graph) or Ponder
Your own server (off-chain) delivery addresses, notifications, caching an ordinary backend, never holding users' private keys

The flow: the frontend reads through RPC or the indexer, the wallet signs transactions, the contracts change state and emit events, the indexer reads those events, and the frontend shows the result.

The checklist from lesson 1 to 17

# Lesson slug What this project uses from it
1 blockchain-fundamentals on-chain data is public and permanent, so personal data stays off-chain
2 ethereum-smart-contracts accounts, gas, the local chain 31337 and Sepolia 11155111
3 wallet-metamask-integration connecting a wallet, switching chains, SIWE login
4 solidity-basics state, events, custom errors in RakaPoints
5 ethers-js-viem clients, calldata, parseUnits('100', 18)
6 reading-blockchain-data eth_call, getLogs, latest vs finalized
7 sending-transactions receipts, a revert still pays gas, simulate first
8 erc20-token the ERC-20 RakaPoints, approve only what is needed
9 erc721-nft CoffeeEditionShirt, _safeMint, SoldOut() at #101
10 dapp-frontend-wagmi-react the "your PTS" component with wagmi
11 smart-contract-testing-hardhat 11 tests, fixtures, coverage
12 ipfs-decentralized-storage the coffee/ metadata folder and its CID in _baseURI
13 defi-basics-untuk-devs not used by this shop yet; needed if PTS goes into an AMM pool (slippage, oracles)
14 gas-optimization measuring gas, the optimizer for deploys
15 smart-contract-security access control, Slither, audits
16 the-graph-indexing a subgraph for Account, Transfer and Shirt
17 l2-scaling-solutions the option of deploying to a cheaper L2

The order to build in

  1. Contracts + tests on the local chain (lessons 4, 8, 9, 11): npx hardhat test must be green, failure paths included.
  2. Metadata to IPFS (lesson 12): upload the coffee/ folder, note its CID, write it into _baseURI.
  3. Local deploy + the shop script (lesson 7): the next section.
  4. Frontend against the local chain (lesson 10), with contract addresses read from the deploy output file.
  5. Indexer (lesson 16) starting at the deploy block.
  6. Testnet: Sepolia, or an L2 testnet such as OP Sepolia (lesson 17), then source code verification.
  7. Mainnet preparation: the section "Before mainnet".

Why IPFS before the deploy? _baseURI in CoffeeEditionShirt is a pure function that returns a fixed string, and a deployed contract can't be edited. A CID you only get after the deploy can't be put in; Raka has to deploy again, at a new address.

Run everything on the local chain

// scripts/deploy.ts: deploy RakaPoints and CoffeeEditionShirt, then save their addresses for scripts, the frontend and the subgraph
import { writeFileSync } from "node:fs";
import { network } from "hardhat";
import { getAddress } from "viem";

const { viem, networkName } = await network.getOrCreate();
const publicClient = await viem.getPublicClient();
const [raka] = await viem.getWalletClients();

const points = await viem.sendDeploymentTransaction("RakaPoints");
const pointsReceipt = await publicClient.waitForTransactionReceipt({ hash: points.deploymentTransaction.hash });
const shirts = await viem.sendDeploymentTransaction("CoffeeEditionShirt");
const shirtsReceipt = await publicClient.waitForTransactionReceipt({ hash: shirts.deploymentTransaction.hash });

console.log(`network ${networkName}, chain ID ${await publicClient.getChainId()}, deployer ${getAddress(raka.account.address)}`);
console.log(`RakaPoints         ${points.contract.address}  block ${pointsReceipt.blockNumber}  gas ${pointsReceipt.gasUsed}`);
console.log(`CoffeeEditionShirt ${shirts.contract.address}  block ${shirtsReceipt.blockNumber}  gas ${shirtsReceipt.gasUsed}`);

writeFileSync(
  `deployments/${networkName}.json`,
  JSON.stringify({ RakaPoints: points.contract.address, CoffeeEditionShirt: shirts.contract.address, startBlock: Number(pointsReceipt.blockNumber) }, null, 2),
);

A second script, scripts/shop.ts, reads deployments/localhost.json, then runs one day at the shop: four purchases (earn), COFFEE #1 minted for Dinda and #2 for Yoga, Dinda redeeming 100 PTS, and Yoga trying to redeem 200 through simulate (so a transaction that is sure to fail is never sent). This is real output from Hardhat 3.19.0 on a fresh local chain (public test accounts, no real money):

$ npx hardhat test
11 passing (2 solidity, 9 nodejs)

$ npx hardhat node                       # another terminal: the local chain 31337
$ npx hardhat run scripts/deploy.ts --network localhost
network localhost, chain ID 31337, deployer 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
RakaPoints         0x5FbDB2315678afecb367f032d93F642f64180aa3  block 1  gas 1229240
CoffeeEditionShirt 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512  block 2  gas 1999101

$ npx hardhat run scripts/shop.ts --network localhost
block 3  earn(Dinda, 9500)   Coffee Print Shirt gas 73204  success
block 4  earn(Yoga, 7500)    Plain Black Shirt  gas 56092  success
block 5  earn(Yoga, 4000)    Raka Cap           gas 38992  success
block 6  earn(Dinda, 6500)   Coffee Print Mug   gas 39004  success
block 7  mint COFFEE #1 for Dinda               gas 96559  success
block 8  mint COFFEE #2 for Yoga                gas 79447  success
block 9  Dinda redeems 100 PTS                  gas 35679  success
Error: ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed)
                               (0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC, 115000000000000000000, 200000000000000000000)
PTS Dinda 60, Yoga 115, totalSupply 175
COFFEE #1 owned by 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 (Dinda)
tokenURI(1) = ipfs://bafybeicske33e77e3uujpvrkwi6ynpy3dpo7hbkaelixuxkaxfvebus37q/1
Transfer RakaPoints: 5 logs, head block 9

Frontend, indexer, and L2

The frontend uses the "your PTS" component from the dapp-frontend-wagmi-react lesson as it is; only the chain list and the addresses change:

import { createConfig, http } from 'wagmi'
import { hardhat, sepolia, optimismSepolia } from 'wagmi/chains'
import { injected } from 'wagmi/connectors'

export const config = createConfig({
  chains: [hardhat, sepolia, optimismSepolia],
  connectors: [injected()],
  transports: { [hardhat.id]: http(), [sepolia.id]: http(), [optimismSepolia.id]: http() },
})

The subgraph from the the-graph-indexing lesson gets one more data source for COFFEE (address 0xe7f1...0512, startBlock: 2, event Transfer(indexed address,indexed address,indexed uint256)) with a Shirt { id, owner, mintedAtBlock } entity; its graph build and Matchstick test pass. For an L2, add an opSepolia network to hardhat.config.ts (the l2-scaling-solutions lesson), run npx hardhat run scripts/deploy.ts --network opSepolia, and deployments/opSepolia.json gets its addresses. Keep addresses per chain ID, not in one constant.

When you need your own server

Contracts suit the rules everyone must trust: who has how many PTS, who owns COFFEE #1. An ordinary (off-chain) server is still needed for:

What it must not do: store users' private keys or sign on their behalf. That is the wallet's job.

Before mainnet

This tutorial stops at testnets. If these contracts ever hold real value:

⚠️ Mistakes you only find after the deploy

TL;DR: Raka's Shirt Shop's full dApp is smart contracts (RakaPoints ERC-20 and CoffeeEditionShirt ERC-721) as the trusted backend, a wallet to sign, a React + wagmi frontend, metadata on IPFS, an indexer for rankings and history, and an ordinary server for data that doesn't need to be on-chain, notifications and caching (never holding users' private keys). The order: contracts + tests, IPFS metadata (the CID must exist before the deploy because _baseURI can't change), local deploy + script, frontend, indexer, testnet (Sepolia or an L2 testnet) + verification. On the local chain: 11 tests pass, RakaPoints at 0x5FbD...0aa3, CoffeeEditionShirt at 0xe7f1...0512, Dinda left with 60 PTS after her redeem, Yoga refused with ERC20InsufficientBalance in the simulation. Before mainnet: an audit, source verification, the owner key in a hardware wallet or a multisig.

⚡ One dApp, six pieces

Meaning: Smart contracts hold the trusted rules and data, the wallet signs, the frontend shows, IPFS keeps big files, an indexer sums up the history, and your own server keeps what doesn't need to be on-chain.

⚡ IPFS first, then deploy

Guess first: why must the metadata go to IPFS before CoffeeEditionShirt is deployed?

_baseURI is a fixed string, and a deployed contract can't be edited. A CID you only get after the deploy can't be put in, so Raka would have to deploy again, at a new address.

Meaning: The order: contracts + tests, IPFS metadata, local deploy + script, frontend, indexer, then testnet.

⚡ A day at the shop, on the local chain

Write:

npx hardhat run scripts/deploy.ts --network localhost
npx hardhat run scripts/shop.ts --network localhost

Meaning: Four purchases, COFFEE #1 for Dinda, Dinda redeems 100 PTS and has 60 left, while Yoga is refused with ERC20InsufficientBalance in the simulation, before any gas is spent.

⚡ An ordinary server is still needed

Meaning: For data that doesn't need to be on-chain or mustn't be public (delivery addresses), notifications and caching. The server must never store users' private keys or sign on their behalf.

What you will learn