Building a project with Scaffold-ETH-2 | Crowd Fund | Part One

WebSculpt
3 min readDec 11, 2023

--

Image from Shubham Dhage on Unsplash

If you haven’t heard of Scaffold-ETH-2 (SE-2) before, check out my Intro into Scaffold-ETH-2.
Want to learn a little bit more before you get started? Here’s a post about writing, reading, and listening to Smart Contracts.

For this series, we’ll iterate over multiple versions of a “Crowd Funding” dApp that allows users to receive donations. We’ll start with a small contract that serves as a good foundation. The dApp will then get an overhaul so that it allows for multiple people to be the owner of a “Fund Run”. We’ll build two versions that represent extremes: V2 will store everything on-chain (we’ll discuss why this isn’t practical), while V3 will use The Graph (subgraphs).

More about Crowd Fund (what we’re going to build).

Crowd Fund is a basic “crowdfunding” app that allows for multiple users to ask for donations. The smart contract keeps donations separated so that a user can donate to multiple funds without any mix-ups when it comes time to withdraw. Timed Deadlines and Money Targets present conditions that must be met before a fund releases any of its Ether. Owners (of a fund) can only collect donations after their fund is successful, while Donors’ funds are accessible for return in the event a fund fails to meet its Money Target.

Crowd Fund V1

Live Demo
GitHub
Contract (on Sepolia)
On BuidlGuidl

It’s a bare-bones foundation — something small that acts as a primer to SE-2 — but also something that we can continue to add on to. These “Fund Runs” will only have one owner, so the rules are simple:

  • These Fund Runs have deadlines (defined in minutes by the user during Fund Run creation)
  • Fund Runs also have a target money goal
  • A donor can get their funds back from a Fund Run IF:
    – The deadline has passed
    – The fund failed to raise its target capital
  • An owner can get their new donations IF:
    – The deadline has passed
    – The fund’s donations are greater-than/equal-to the target money goal

Multisig Crowd Fund (V2)

Live Demo
GitHub
Contract (on Sepolia)
On BuidlGuidl
View Proposals

Everything about V1 changes here, with the ability for Fund Runs to have multiple owners. This multisig implementation means that these “Vaults” require that all owners support a “Proposal” before any would-be transactions can occur. Single-Wallet Fund Runs are still available, and Multisig Vaults can be created with 2 or 3 owners. Proposals can be revoked, but only by the user who created them. Each Vault uses its own nonce; while Vaults do not interfere with one another, Proposals within a Vault should be processed in order.

For learning-purposes, recall that V2 and V3 will represent extremes. V2 has a pretty big contract, because it is storing everything on-chain. This means that this contract has a lot of interesting solidity to learn from, but it wouldn’t be practical on mainnet. That’s where V3 comes in…

Multisig Crowd Funds on The Graph (V3)

While V2 stored everything on-chain, this version uses a Subgraph to allow for the querying of Fund Runs and Proposals (as well as their statuses).

Live Demo
GitHub
Contract (on Sepolia)
On BuidlGuidl
View Proposals
View Queries (data)
View Queries (code)

This is a re-write of V2’s Smart Contract which makes it queryable via the contract’s events (removing the bulky structs, mappings, and arrays that allowed us to read these multisig proposals directly from the blockchain).

You can view these queries here.

Ready to get started?

The next posts:

--

--

WebSculpt

Blockchain Development, coding on Ethereum. Condensed notes for learning to code in Solidity faster.