Token-Based Loyalty Program on Stacks Blockchain
GratiFi is a decentralized loyalty program built on the Stacks blockchain. It allows businesses to reward loyal customers with tokenized loyalty points, which can be redeemed for various rewards. The contract ensures secure and transparent transactions, enabling users to earn, transfer, and redeem points seamlessly.
-
Tokenized Loyalty System:
Customers earn and accumulate loyalty tokens called LoyaltyTokens (LYT) for their interactions and purchases. -
Secure Transfers:
Users can transfer tokens between accounts, fostering a decentralized exchange of rewards. -
Customizable Rewards:
Businesses can add rewards with unique names, costs, and availability, providing a personalized loyalty experience. -
Transparent Redemption:
Customers can redeem their tokens for available rewards, with all transactions recorded on the blockchain.
| Error Code | Description |
|---|---|
ERR-NOT-AUTHORIZED (100) |
Caller is not authorized to perform the action. |
ERR-INSUFFICIENT-BALANCE (101) |
Insufficient balance to complete the transaction. |
ERR-INVALID-AMOUNT (102) |
Invalid token or reward amount. |
ERR-REWARD-NOT-AVAILABLE (103) |
Requested reward is not available. |
-
Balances
Tracks the token balance of each user.(define-map balances principal uint)
-
Rewards
Stores details of available rewards.(define-map rewards uint {name: (string-ascii 50), cost: uint, available: uint})
-
Contract Variables
token-name– The name of the token (LoyaltyToken).token-symbol– The symbol of the token (LYT).owner– The contract owner who can manage rewards and mint tokens.
-
(get-name)
Returns the token name.(define-read-only (get-name) (ok (var-get token-name)))
-
(get-symbol)
Returns the token symbol.(define-read-only (get-symbol) (ok (var-get token-symbol)))
-
(get-balance (account principal))
Returns the balance of a specified account.(define-read-only (get-balance (account principal)) (ok (default-to u0 (map-get? balances account))))
-
(get-reward (reward-id uint))
Retrieves the details of a reward by its ID.(define-read-only (get-reward (reward-id uint)) (map-get? rewards reward-id))
-
(transfer (amount uint) (sender principal) (recipient principal))
Transfers tokens from one account to another.- Errors:
ERR-NOT-AUTHORIZEDif the caller is not the sender.ERR-INSUFFICIENT-BALANCEif the sender has insufficient tokens.
- Errors:
-
(mint (amount uint) (recipient principal))
Mints new tokens and assigns them to the specified recipient.- Authorized: Only the contract owner can mint tokens.
-
(add-reward (name string-ascii) (cost uint) (available uint))
Adds a new reward to the system.- Authorized: Only the contract owner can add rewards.
-
(redeem-reward (reward-id uint))
Allows users to redeem tokens for a specified reward.- Errors:
ERR-INSUFFICIENT-BALANCEif the user does not have enough tokens.ERR-REWARD-NOT-AVAILABLEif the reward is out of stock.
- Errors:
- Deploy the
GratiFicontract on the Stacks blockchain. - The deploying account becomes the contract owner.
The contract owner can mint new loyalty tokens using the mint function:
(mint u1000 'SP3FBR2AGK71QQCPBBFAKXPTZSDZ5WYB6N4XVESYZ)Add a reward that customers can redeem:
(add-reward "Free Coffee" u50 u100) ;; 50 tokens for a coffee, 100 availableUsers can transfer tokens to others:
(transfer u100 'SP3FBR2AGK71QQCPBBFAKXPTZSDZ5WYB6N4XVESYZ 'SP3WPYF4XJGM5G4Q2BZJ5SMX7Q98A4J4KSV6PPTX)Users can redeem tokens for a reward:
(redeem-reward u0) ;; Redeems reward with ID 0- Only the contract owner can mint tokens and add rewards.
- Transfers and redemptions are validated to ensure sufficient balance and availability.
- All transactions are recorded immutably on the blockchain for transparency and accountability.
- Reward Expiry: Implement expiration dates for rewards.
- Dynamic Token Supply: Introduce mechanisms for burning tokens.
- Multisig Ownership: Allow multiple owners to manage the contract collaboratively.
- NFT Rewards: Expand the system to include NFTs as redeemable rewards.
This project is licensed under the MIT License.