Add functionality to verify that users hold a minimum balance of specified ERC20 tokens. This will allow for token-gated access to certain features or groups within the Discourse forum based on on-chain assets.
Purpose
- Enable admins to create token-gated communities within Discourse
- Verify token ownership
- Create a foundation for Web3-based permissions within the forum
Technical Requirements
Implementation Details
The implementation will need to:
- Allow admins to specify token contract addresses and minimum balances
- Connect to user's wallet to verify token holdings (read-only)
- Store verification results securely
- Re-verify balances periodically
- Assign users to groups based on verification results
Example Code Snippet
// Client-side token balance verification
window.checkTokenBalance = async function(tokenAddress, minAmount) {
try {
if (!window.ethereum) throw new Error("No wallet connected");
const web3 = new Web3(window.ethereum);
const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' });
const userAddress = accounts[0];
// ERC20 minimum ABI for balanceOf
const erc20MinABI = [
{
constant: true,
inputs: [{ name: "_owner", type: "address" }],
name: "balanceOf",
outputs: [{ name: "balance", type: "uint256" }],
type: "function",
},
{
constant: true,
inputs: [],
name: "decimals",
outputs: [{ name: "decimals", type: "uint8" }],
type: "function",
}
];
const contract = new web3.eth.Contract(erc20MinABI, tokenAddress);
const decimals = await contract.methods.decimals().call();
const balance = await contract.methods.balanceOf(userAddress).call();
const readableBalance = balance / (10 ** decimals);
return {
hasMinimum: readableBalance >= minAmount,
balance: readableBalance
};
} catch (error) {
console.error("Error checking token balance:", error);
return { hasMinimum: false, balance: 0 };
}
};
Acceptance Criteria
Resources
Add functionality to verify that users hold a minimum balance of specified ERC20 tokens. This will allow for token-gated access to certain features or groups within the Discourse forum based on on-chain assets.
Purpose
Technical Requirements
Implementation Details
The implementation will need to:
Example Code Snippet
Acceptance Criteria
Resources