A decentralized Clarity smart contract for managing church offerings, tithes, donations, and fundraising campaigns on the Stacks blockchain.
This smart contract provides a transparent and immutable system for churches to receive and manage financial contributions. All transactions are recorded on-chain, ensuring complete accountability and transparency for church members and leadership.
- Members can give offerings and tithes separately
- Individual contribution history tracking
- Automatic treasury balance updates
- Real-time total calculations
- Create time-bound fundraising campaigns with specific goals
- Track donations per campaign and per donor
- Campaign creators and contract owner can close campaigns
- Automatic expiration based on block height
- Owner can add/remove authorized pastors
- Role-based access control for future feature expansion
- Secure authorization checks
- Centralized treasury with balance tracking
- Single recipient withdrawals
- Emergency withdrawal function
- Batch distribution to up to 10 recipients simultaneously
- Read-only functions for public accountability
- View total offerings, tithes, and treasury balance
- Check individual member contributions
- Monitor campaign progress and donations
Purpose: Record a member's offering contribution
Parameters:
amount: Amount in microSTX to donate Returns: Amount donated Example:(contract-call? .church-offering give-offering u1000000)
Purpose: Record a member's tithe contribution
Parameters:
amount: Amount in microSTX to donate Returns: Amount donated
Purpose: Create a new fundraising campaign
Parameters:
name: Campaign name (max 100 characters)goal: Target amount in microSTXduration: Number of blocks until campaign expires Returns: Campaign ID Example:(contract-call? .church-offering create-campaign "Building Fund" u50000000 u144)
Purpose: Donate to a specific campaign
Parameters:
campaign-id: ID of the campaignamount: Donation amount in microSTX Returns: Amount donated
Purpose: Close an active campaign (creator or owner only)
Parameters:
campaign-id: ID of the campaign to close Returns: Success boolean
Purpose: Authorize a new pastor
Access: Contract owner only
Parameters:
pastor: Principal address of the pastor
Purpose: Remove pastor authorization
Access: Contract owner only
Parameters:
pastor: Principal address of the pastor
Purpose: Withdraw specific amount from treasury
Access: Contract owner only
Parameters:
amount: Amount to withdraw in microSTXrecipient: Destination address
Purpose: Withdraw entire treasury balance
Access: Contract owner only
Parameters:
recipient: Destination address
Purpose: Distribute funds to multiple recipients in one transaction
Access: Contract owner only
Parameters:
recipients: List of up to 10 recipient/amount pairs Example:
(contract-call? .church-offering distribute-funds
(list
{recipient: 'SP..., amount: u1000000}
{recipient: 'SP..., amount: u2000000}
)
)Returns: Total offerings received (uint)
Returns: Total tithes received (uint)
Returns: Current treasury balance (uint)
Returns: Total offerings from specific member (uint)
Returns: Total tithes from specific member (uint)
Returns: Whether address is an authorized pastor (bool)
Returns: Campaign details or none
Returns: Amount donated by specific donor to campaign (uint)
Returns: Actual STX balance held by contract (uint)
| Code | Constant | Description |
|---|---|---|
| u100 | err-owner-only | Action requires contract owner |
| u101 | err-insufficient-balance | Treasury balance too low |
| u102 | err-invalid-amount | Amount must be greater than zero |
| u103 | err-not-authorized | Caller not authorized |
| u104 | err-pastor-not-found | Pastor address not found |
| u105 | err-campaign-not-found | Campaign ID doesn't exist |
| u106 | err-campaign-ended | Campaign is closed or expired |
| u107 | err-already-exists | Resource already exists |
- Stacks CLI or Clarinet installed
- Testnet or Mainnet STX for deployment
- Test the contract:
clarinet check
clarinet test- Deploy to testnet:
clarinet deploy --testnet- Deploy to mainnet:
clarinet deploy --mainnet✅ Implemented Security Features:
- Owner-only access control for critical functions
- Balance validation prevents over-withdrawal
- Amount validation ensures positive values
- Campaign time-bound validation
- Duplicate prevention for pastor additions
- Input validation for all user-provided data
- Contract owner has full withdrawal access (use multi-sig wallet recommended)
- All transactions are permanent and visible on-chain
- Test thoroughly on testnet before mainnet deployment
- Consider implementing multi-signature for production use
- Weekly Offerings: Members can contribute offerings remotely
- Tithe Management: Separate tracking for tithe contributions
- Building Funds: Create campaigns for construction projects
- Mission Trips: Fundraise for specific mission activities
- Community Outreach: Track donations for charity programs
- Transparent Reporting: Provide members with on-chain proof of contributions
- Use Multi-Signature Wallets: For the contract owner address in production
- Regular Audits: Review treasury balance and distributions regularly
- Campaign Durations: Set realistic timeframes (144 blocks ≈ 1 day)
- Amount Conversions: Remember 1 STX = 1,000,000 microSTX
- Backup Plans: Always have emergency withdrawal procedures documented
Test all functions thoroughly:
;; Test offering
(contract-call? .church-offering give-offering u1000000)
;; Test campaign creation
(contract-call? .church-offering create-campaign "Test Campaign" u10000000 u1000)
;; Check balances
(contract-call? .church-offering get-treasury-balance)