The Community Funding Platform is a decentralized smart contract built on the Stacks blockchain that enables community-driven funding for local initiatives. Community members can contribute to a shared funding pool, propose funding requests for verified initiatives, vote on proposals, and collectively distribute funds through a democratic process.
- Initiative Registration: Anyone can register a community initiative with details like name, category, and description
- Verification System: Contract owner can verify legitimate initiatives before they become eligible for funding
- Community Contributions: Members contribute STX tokens to build a collective funding pool
- Democratic Proposals: Eligible contributors can create funding requests for verified initiatives
- Voting Mechanism: Contributors vote on funding proposals with a time-limited voting period
- Automated Execution: Approved proposals automatically transfer funds to initiatives
- Initiative Management: Initiative owners can update information and deactivate their listings
Initiatives Map
{
initiative-id: uint,
owner: principal,
name: string-ascii 50,
category: string-ascii 30,
description: string-ascii 200,
wallet: principal,
verified: bool,
funding-received: uint,
registration-block: uint,
active: bool
}Funding Requests Map
{
request-id: uint,
initiative-id: uint,
amount: uint,
proposer: principal,
votes-for: uint,
votes-against: uint,
voting-ends: uint,
executed: bool,
description: string-ascii 150
}Contributions Map
{
contributor: principal,
total-contributed: uint,
last-contribution: uint
}Register a new community initiative.
Parameters:
name: Initiative name (max 50 characters)category: Initiative category (max 30 characters)description: Detailed description (max 200 characters)wallet: Principal address to receive funds
Returns: Initiative ID
Example:
(contract-call? .community-funding register-initiative
"Local Art Gallery"
"Arts & Culture"
"A community space for local artists to showcase their work"
'SP2...WALLET)Verify an initiative as legitimate (contract owner only).
Parameters:
initiative-id: ID of the initiative to verify
Returns: true on success
Add funds to the community funding pool.
Parameters:
amount: Amount in microSTX (1 STX = 1,000,000 microSTX)
Returns: Amount contributed
Example:
(contract-call? .community-funding contribute-to-pool u5000000) ;; 5 STXCreate a proposal to fund an initiative.
Requirements:
- Caller must have contributed at least the minimum amount (1 STX)
- Initiative must be verified and active
- Request amount must not exceed available pool balance
Parameters:
initiative-id: Target initiative IDamount: Requested funding amount in microSTXdescription: Proposal description (max 150 characters)
Returns: Request ID
Vote on a funding request.
Requirements:
- Caller must be an eligible voter (contributed minimum amount)
- Must not have already voted on this request
- Voting period must still be active
Parameters:
request-id: ID of the funding requestsupport:trueto vote for,falseto vote against
Returns: Vote value (true/false)
Execute an approved funding request.
Requirements:
- Voting period must have ended
- Must have minimum required votes (default: 3)
- Must have more votes for than against
- Request must not have been executed already
Parameters:
request-id: ID of the request to execute
Returns: Amount transferred
Update initiative details (owner only).
Parameters:
initiative-id: ID of the initiativename: New namedescription: New description
Returns: true on success
Deactivate an initiative (owner or contract owner).
Parameters:
initiative-id: ID of the initiative to deactivate
Returns: true on success
Emergency fund withdrawal (contract owner only).
Parameters:
amount: Amount to withdrawrecipient: Recipient address
Returns: Amount withdrawn
get-initiative: Retrieve initiative details by IDget-request: Retrieve funding request details by IDget-vote: Check if an address voted on a specific requestget-contribution: Get contribution stats for an addressget-total-funding-pool: Get current pool balanceget-initiative-count: Get total number of registered initiativesget-request-count: Get total number of funding requestsis-eligible-voter: Check if an address can vote
- Minimum Funding Amount: 1 STX (1,000,000 microSTX) - minimum contribution to become eligible voter
- Voting Period: 144 blocks (~24 hours) - duration of voting on proposals
- Minimum Votes Required: 3 votes - minimum votes needed for proposal execution
| Code | Constant | Description |
|---|---|---|
| u100 | ERR-NOT-AUTHORIZED | Unauthorized action |
| u101 | ERR-INITIATIVE-NOT-FOUND | Initiative doesn't exist |
| u102 | ERR-INITIATIVE-ALREADY-EXISTS | Initiative already registered |
| u103 | ERR-INSUFFICIENT-FUNDS | Not enough funds in pool |
| u104 | ERR-INVALID-AMOUNT | Invalid amount specified |
| u105 | ERR-REQUEST-NOT-FOUND | Funding request doesn't exist |
| u106 | ERR-ALREADY-VOTED | User already voted on this request |
| u107 | ERR-VOTING-PERIOD-ENDED | Voting period has ended/not ended |
| u108 | ERR-NOT-ELIGIBLE | User not eligible to perform action |
| u109 | ERR-INVALID-INPUT | Invalid input parameter |
-
Setup
- Deploy contract (deployer becomes contract owner)
- Community members contribute to funding pool
-
Initiative Registration
- Initiative owner registers their project
- Contract owner verifies the initiative
-
Funding Request
- Eligible contributor creates funding request
- Community members vote during voting period
- If approved, anyone executes the request to transfer funds
-
Fund Distribution
- Funds automatically transferred to initiative wallet
- Initiative's funding-received counter updated
- Pool balance reduced accordingly
- Input validation on all user-supplied data
- Range checks on IDs to prevent invalid references
- String validation to prevent empty inputs
- Authorization checks for privileged operations
- Vote tracking to prevent double-voting
- Time-locked voting periods
- Balance verification before transfers
- Deploy the contract to Stacks blockchain
- Note the contract address for user interactions
- Configure minimum amounts and voting periods if needed
- Begin accepting initiative registrations
- Test initiative registration with valid/invalid inputs
- Verify contribution and eligibility system
- Test voting mechanics and time constraints
- Confirm proposal execution logic
- Test emergency withdrawal functionality
- Verify authorization controls