A robust, production-ready Clarity smart contract for decentralized gaming guild management with automated profit sharing and member earnings distribution on the Stacks blockchain.
The Gaming Guild Profit Sharing contract enables gaming communities to organize as decentralized guilds with transparent, automated profit distribution. Guild owners manage membership and earnings, while members receive fair compensation based on their assigned share percentages.
- Guild Management - Create and manage multiple gaming guilds with unique identities and ownership
- Member Management - Add/remove members with customizable profit share percentages (1-100%)
- Profit Tracking - Track guild profitability and member earnings with precision
- Automated Distribution - Distribute profits fairly based on member share percentages
- Earnings Claims - Members can claim their earned amounts at any time
- Security - Owner-only authorization, input validation, and comprehensive error handling
- Data Integrity - Maintains detailed records of all transactions and member activity
Creates a new gaming guild and registers the creator as the first member. ``` (create-guild (name (string-ascii 64)) (initial-share uint)) ```
- Parameters:
name: Guild name (1-64 ASCII characters)initial-share: Creator's profit share (1-100)
- Returns: Guild ID on success
- Errors: Invalid input, invalid share percentage
Adds a new member to an existing guild (owner only). ``` (add-member (guild-id uint) (new-member principal) (share uint)) ```
- Parameters:
guild-id: Target guild IDnew-member: Member principal addressshare: Profit share percentage (1-100)
- Returns:
ok trueon success - Errors: Guild not found, unauthorized, member exists, invalid share
Removes a member from a guild (owner only). ``` (remove-member (guild-id uint) (member principal)) ```
- Parameters:
guild-id: Target guild IDmember: Member principal to remove
- Returns:
ok trueon success - Errors: Guild not found, unauthorized, member not found
Deposits profit into a guild (owner only). ``` (deposit-profit (guild-id uint) (amount uint)) ```
- Parameters:
guild-id: Target guild IDamount: Profit amount to deposit
- Returns: Deposited amount on success
- Errors: Guild not found, unauthorized, invalid input
Distributes profits to active members based on share percentages (owner only). ``` (distribute-profits (guild-id uint) (profit-amount uint)) ```
- Parameters:
guild-id: Target guild IDprofit-amount: Amount to distribute
- Returns: Distributed amount on success
- Errors: Guild not found, unauthorized, no profits
Allows members to claim their earned amounts. ``` (claim-earnings (guild-id uint) (amount uint)) ```
- Parameters:
guild-id: Guild IDamount: Amount to claim
- Returns: Claimed amount on success
- Errors: Guild not found, member not found, insufficient balance
Updates a member's profit share percentage (owner only). ``` (update-member-share (guild-id uint) (member principal) (new-share uint)) ```
- Parameters:
guild-id: Target guild IDmember: Member principalnew-share: New share percentage (1-100)
- Returns:
ok trueon success - Errors: Guild not found, unauthorized, member not found, invalid share
Retrieves guild information.
```
(get-guild-info (guild-id uint))
```
Returns: { name, owner, created-at, total-profit, active-members } or none
Retrieves member information.
```
(get-member-info (guild-id uint) (member principal))
```
Returns: { share-percentage, joined-at, total-earned, pending-withdrawal, active } or none
Gets the current balance of a guild. ``` (get-guild-balance (guild-id uint)) ``` Returns: Balance amount (uint)
Gets the total contract balance. ``` (get-contract-balance) ``` Returns: Total balance (uint)
Gets the total number of guilds created. ``` (get-total-guilds) ``` Returns: Total guilds count (uint)
| Code | Error | Description |
|---|---|---|
| 400 | ERR-INVALID-INPUT | Invalid input parameters |
| 401 | ERR-UNAUTHORIZED | Caller is not authorized |
| 402 | ERR-INSUFFICIENT-BALANCE | Insufficient balance for operation |
| 404 | ERR-GUILD-NOT-FOUND | Guild does not exist |
| 405 | ERR-MEMBER-NOT-FOUND | Member does not exist |
| 406 | ERR-MEMBER-EXISTS | Member already exists in guild |
| 407 | ERR-NO-PROFITS | No profits to distribute |
| 408 | ERR-INVALID-SHARE | Share percentage outside valid range (1-100) |
- Clarinet (Stacks development environment)
- STX tokens for network fees
-
Install Clarinet ```bash npm install -g @hirosystems/clarinet ```
-
Clone the repository ```bash git clone cd gaming-guild ```
-
Deploy to testnet ```bash clarinet deployments generate --testnet ```
-
Deploy to mainnet ```bash clarinet deployments generate --mainnet ```
;; 1. Create a new guild
(contract-call? .gaming-guild create-guild "Legends Guild" u25)
;; Returns: u1 (guild ID)
;; 2. Add members to the guild
(contract-call? .gaming-guild add-member u1 'SP2X2JC3WGMQ9N38JFNM2K8G2J1F2H4N5K6P7Q8R u20)
;; 3. Deposit profits
(contract-call? .gaming-guild deposit-profit u1 u1000)
;; 4. Distribute profits to members
(contract-call? .gaming-guild distribute-profits u1 u1000)
;; 5. Members claim earnings
(contract-call? .gaming-guild claim-earnings u1 u250)
;; 6. Query guild info
(contract-call? .gaming-guild get-guild-info u1)