Community Incentive Manager: Token and Reward Management
1.1 Community Incentive Manager Overview
Community Incentive Manager module provides functionalities for creating and managing community incentives, specifically using tokens and NFTs to reward active participation and contributions in a DAO or decentralized governance system. This module is designed to motivate community members through token-based rewards and NFT issuance, helping to maintain an active and engaged community.
1.2 Smart Contracts for Token and NFT Issuance
1.2.1 ERC-20 Token Contract for Reward Distribution
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract RewardToken is ERC20 {
address public admin;
constructor() ERC20("CommunityReward", "CRWD") {
admin = msg.sender;
_mint(admin, 1000000 * 10 ** decimals());
}
// Issue tokens to active community members
function issueReward(address to, uint256 amount) external {
require(msg.sender == admin, "Only admin can issue rewards");
_transfer(admin, to, amount);
}
}
1.2.2 ERC-721 NFT Contract for Achievements
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
contract AchievementNFT is ERC721 {
using Counters for Counters.Counter;
Counters.Counter private _tokenIdCounter;
address public admin;
constructor() ERC721("CommunityAchievement", "ACHV") {
admin = msg.sender;
}
// Mint NFT for special community achievements
function mintAchievement(address recipient, string memory uri) external {
require(msg.sender == admin, "Only admin can mint achievements");
uint256 tokenId = _tokenIdCounter.current();
_tokenIdCounter.increment();
_safeMint(recipient, tokenId);
_setTokenURI(tokenId, uri);
}
}
1.3 Interaction with Web3.js for Reward Issuance
1.3.1 Issuing ERC-20 Tokens
const Web3 = require('web3');
const web3 = new Web3("https://your_rpc_url");
const rewardTokenAddress = "0xYourTokenAddress";
const rewardTokenAbi = [ /* ABI for RewardToken contract */ ];
const rewardTokenContract = new web3.eth.Contract(rewardTokenAbi, rewardTokenAddress);
async function issueTokenReward(memberAddress, amount, adminPrivateKey) {
const tx = rewardTokenContract.methods.issueReward(memberAddress, amount);
const gas = await tx.estimateGas({ from: adminAddress });
const data = tx.encodeABI();
const signedTx = await web3.eth.accounts.signTransaction({
to: rewardTokenAddress,
data,
gas
}, adminPrivateKey);
const receipt = await web3.eth.sendSignedTransaction(signedTx.rawTransaction);
console.log(`Token reward issued to ${memberAddress}: ${receipt.transactionHash}`);
}
issueTokenReward("0xMemberAddress", 100, "0xAdminPrivateKey");
1.3.2 Minting an Achievement NFT
const achievementNFTAddress = "0xYourNFTAddress";
const achievementNFTAbi = [ /* ABI for AchievementNFT contract */ ];
const achievementNFTContract = new web3.eth.Contract(achievementNFTAbi, achievementNFTAddress);
async function mintAchievementNFT(recipientAddress, tokenURI, adminPrivateKey) {
const tx = achievementNFTContract.methods.mintAchievement(recipientAddress, tokenURI);
const gas = await tx.estimateGas({ from: adminAddress });
const data = tx.encodeABI();
const signedTx = await web3.eth.accounts.signTransaction({
to: achievementNFTAddress,
data,
gas
}, adminPrivateKey);
const receipt = await web3.eth.sendSignedTransaction(signedTx.rawTransaction);
console.log(`NFT achievement minted for ${recipientAddress}: ${receipt.transactionHash}`);
}
mintAchievementNFT("0xRecipientAddress", "ipfs://tokenURI", "0xAdminPrivateKey");
Last updated