BC10: Capstone: a shared fund the group can trust
Project 3: an app on the network
🎯You'll be able to
Complete Project 3: an app that checks its network, keeps keys out of the code, shows exact balances and history, waits for confirmations, and explains every refusal in plain words.
🏠The everyday picture
A passbook printer at the bank: it checks it's connected to the right bank, prints exact amounts, marks new entries "pending" until they clear, and explains a refused withdrawal in words.
📘What it really is
- Network (
connect): stops with "Wrong network" if the chain ID isn't the expected one. - Keys (
loadWallet): fromSAKHI_PRIVATE_KEYonly;.envlisted in.gitignore; the starter'sDEMO_KEYremoved. - Balances and history:
formatEtheron BigInt;Depositedevents in chunks, oldest first. - Deposits: estimate first, send, and wait for the chosen confirmations; several in a row with a nonce manager.
- Errors and retries: custom errors decoded into sentences; reads retried with a time limit.
- The notes (
docs/app-notes.md): networks, keys, confirmations and not verified.
📝A worked example
Input: test 06 failing on the starter: "Replacement transaction underpriced".
Steps:
- Read the test: block making is paused, three deposits are sent, then one block is made; it expects nonces 0, 1 and 2.
- Read the starter: each deposit asks the node for the latest nonce, which is still 0 because nothing has been mined.
- Wrap the wallet in ethers'
NonceManagerinloadWallet, let it assign nonces, and runnpm run test:app.
Expected output: test 06 passes, and all three deposits are in the fund.
🌍Where it's used
- Wallets and payment apps.
- Treasury tools sending several transactions in a row.
- Dashboards reading history from events.
📝Case scenario
A learner's app passed every test except 07: it showed "VM Exception while processing transaction: reverted with custom error..." to
the member. They decoded the error data with the fund's interface and mapped NotMember and IsPaused to plain sentences, and the
test passed.
🖱️Try it
With the practice network running and the contracts deployed, run npm run app -- deposit 0.1 without setting a key. Success: a clear
message naming SAKHI_PRIVATE_KEY, and no key printed.
⚠️Common mistakes
- Reporting success on send. Sign: test 05 fails. Fix: wait for confirmations.
- Rounding balances. Sign: test 03 fails. Fix:
formatEtheron the exact value. - One query for all history. Sign: test 04 fails. Fix: chunks within the step.
🛠️For your project
Project 3's evidence: the output of npm run test:app with 8 passing, docs/app-notes.md, and the app's output against the practice
network.
✅Quick check
Why did the starter's three deposits clash?
Show the answer
Each asked for the latest nonce before any was mined, so they shared one.
What should a member see when the fund is paused?
Show the answer
A plain sentence saying the fund is paused by the admin, with no codes.
