Skip to content

aishaa-umar/Church-Offering-Plate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

Church Offering Plate Smart Contract

A decentralized Clarity smart contract for managing church offerings, tithes, donations, and fundraising campaigns on the Stacks blockchain.

Overview

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.

Features

1. Offerings & Tithes Management

  • Members can give offerings and tithes separately
  • Individual contribution history tracking
  • Automatic treasury balance updates
  • Real-time total calculations

2. Fundraising Campaigns

  • 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

3. Pastor Authorization System

  • Owner can add/remove authorized pastors
  • Role-based access control for future feature expansion
  • Secure authorization checks

4. Treasury Management

  • Centralized treasury with balance tracking
  • Single recipient withdrawals
  • Emergency withdrawal function
  • Batch distribution to up to 10 recipients simultaneously

5. Transparency Features

  • Read-only functions for public accountability
  • View total offerings, tithes, and treasury balance
  • Check individual member contributions
  • Monitor campaign progress and donations

Smart Contract Functions

Public Functions (Member Actions)

give-offering (amount uint)

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)

give-tithe (amount uint)

Purpose: Record a member's tithe contribution
Parameters:

  • amount: Amount in microSTX to donate Returns: Amount donated

create-campaign (name (string-ascii 100)) (goal uint) (duration uint)

Purpose: Create a new fundraising campaign
Parameters:

  • name: Campaign name (max 100 characters)
  • goal: Target amount in microSTX
  • duration: Number of blocks until campaign expires Returns: Campaign ID Example: (contract-call? .church-offering create-campaign "Building Fund" u50000000 u144)

donate-to-campaign (campaign-id uint) (amount uint)

Purpose: Donate to a specific campaign
Parameters:

  • campaign-id: ID of the campaign
  • amount: Donation amount in microSTX Returns: Amount donated

close-campaign (campaign-id uint)

Purpose: Close an active campaign (creator or owner only)
Parameters:

  • campaign-id: ID of the campaign to close Returns: Success boolean

Public Functions (Owner Only)

add-pastor (pastor principal)

Purpose: Authorize a new pastor
Access: Contract owner only
Parameters:

  • pastor: Principal address of the pastor

remove-pastor (pastor principal)

Purpose: Remove pastor authorization
Access: Contract owner only
Parameters:

  • pastor: Principal address of the pastor

withdraw-funds (amount uint) (recipient principal)

Purpose: Withdraw specific amount from treasury
Access: Contract owner only
Parameters:

  • amount: Amount to withdraw in microSTX
  • recipient: Destination address

emergency-withdraw (recipient principal)

Purpose: Withdraw entire treasury balance
Access: Contract owner only
Parameters:

  • recipient: Destination address

distribute-funds (recipients (list 10 {recipient: principal, amount: uint}))

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}
  )
)

Read-Only Functions

get-total-offerings

Returns: Total offerings received (uint)

get-total-tithes

Returns: Total tithes received (uint)

get-treasury-balance

Returns: Current treasury balance (uint)

get-member-offerings (member principal)

Returns: Total offerings from specific member (uint)

get-member-tithes (member principal)

Returns: Total tithes from specific member (uint)

is-pastor (address principal)

Returns: Whether address is an authorized pastor (bool)

get-campaign (campaign-id uint)

Returns: Campaign details or none

get-campaign-donation (campaign-id uint) (donor principal)

Returns: Amount donated by specific donor to campaign (uint)

get-contract-balance

Returns: Actual STX balance held by contract (uint)

Error Codes

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

Deployment

Prerequisites

  • Stacks CLI or Clarinet installed
  • Testnet or Mainnet STX for deployment

Deploy Steps

  1. Test the contract:
clarinet check
clarinet test
  1. Deploy to testnet:
clarinet deploy --testnet
  1. Deploy to mainnet:
clarinet deploy --mainnet

Security Considerations

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

⚠️ Important Notes:

  • 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

Use Cases

  1. Weekly Offerings: Members can contribute offerings remotely
  2. Tithe Management: Separate tracking for tithe contributions
  3. Building Funds: Create campaigns for construction projects
  4. Mission Trips: Fundraise for specific mission activities
  5. Community Outreach: Track donations for charity programs
  6. Transparent Reporting: Provide members with on-chain proof of contributions

Best Practices

  1. Use Multi-Signature Wallets: For the contract owner address in production
  2. Regular Audits: Review treasury balance and distributions regularly
  3. Campaign Durations: Set realistic timeframes (144 blocks ≈ 1 day)
  4. Amount Conversions: Remember 1 STX = 1,000,000 microSTX
  5. Backup Plans: Always have emergency withdrawal procedures documented

Testing

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)

About

This is a Clarity contract built for the Stacks blockchain that modernizes church financial management through blockchain technology. It provides a transparent, immutable, and decentralized platform for receiving offerings, managing tithes, coordinating fundraising campaigns, while maintaining complete accountability through on-chain verification.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors