Study notesWeek 12: Capstone: Build And Deploy A dApp On A Testnet
Week 12 / Blockchain from zero

Capstone: Build And Deploy A dApp

Week 12 · Blockchain

What You Can Do By The End

Week 12 · Blockchain

Recap Of Week 11

Week 12 · Blockchain

The Brief

Week 12 · Blockchain

Project Ideas

IdeaCore feature
Tip jarNotes with ether
CrowdfundingGoal and deadline
Attendance badgeToken per attendee
VotingOne vote per address
Week 12 · Blockchain

Scope In One Sentence

Week 12 · Blockchain

Design On Paper First

state:     tips[address] -> amount
functions: tip(note), withdraw()
events:    Tipped(from, amount, note)
trust:     owner can withdraw all
Week 12 · Blockchain

Reference Contract, Part One

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract TipJar {
    address public immutable owner;
    mapping(address => uint256) public tips;
    event Tipped(address indexed from, uint256 amount, string note);

    constructor() { owner = msg.sender; }
}
Week 12 · Blockchain

Reference Contract, Part Two

function tip(string calldata note) external payable {
    require(msg.value > 0, "send some ether");
    tips[msg.sender] += msg.value;
    emit Tipped(msg.sender, msg.value, note);
}

function withdraw() external {
    require(msg.sender == owner, "only owner");
    (bool ok, ) = owner.call{value: address(this).balance}("");
    require(ok, "withdraw failed");
}
Week 12 · Blockchain

Test Before You Deploy

Week 12 · Blockchain

Deploy And Verify

Week 12 · Blockchain

Connect The Web Page

import { BrowserProvider, Contract, parseEther } from "ethers";
const abi = ["function tip(string note) payable"];
const provider = new BrowserProvider(window.ethereum);
const signer = await provider.getSigner();
const jar = new Contract(ADDRESS, abi, signer);
const tx = await jar.tip("thanks", { value: parseEther("0.001") });
await tx.wait();
20 points

Rubric

CriterionPoints
Purpose and fit4
Contract safety4
Deployment4
Web interaction4
Demo4
Week 12 · Blockchain

Demo Script, Five Minutes

Week 12 · Blockchain

Review Checklist

Week 12 · Blockchain

Recap And What Comes Next

Week 12 · Blockchain

Questions And Lab