← Portfolio/ dream-village
Web3 · Metaverse · Node.js

Dream Village

A gamified metaverse village-building platform with a fully on-chain referral economy. Villagers register crypto wallets, earn LTC commissions through BTCPay Server pull-payments, and gameplay events are secured with HMAC-SHA256 webhook signatures.

Node.jsMySQL 2 (pool)BTCPay ServerLTC On-ChainCrypto HMAC-SHA256React + ViteAxiosdotenv
villagerModel.js — Referral Payout Engine
// Generate HMAC-signed referral code + register wallet
async function registerVillager(userId, ltcAddress) {
  const refCode = generateReferralCode(); // crypto.randomBytes(10).hex
  await pool.query('INSERT INTO villagers SET ?', [{
    user_id: userId, referral_code: refCode,
    ltc_address: ltcAddress, created_at: new Date()
  }]);
  return { refCode, ltcAddress };
}

// BTCPay pull-payment: auto-approve LTC commission
async function payCommission(referrerId, amount) {
  const { ltc_address } = await getVillager(referrerId);
  await payReferral(ltc_address, amount); // btcpay_referral_integration.js
  await pool.query('UPDATE villagers SET total_earned=total_earned+? WHERE id=?', [amount, referrerId]);
}

// HMAC webhook signature verification
function verifyBtcPaySignature(rawBody, sigHeader, secret) {
  const expected = `sha256=${crypto.createHmac('sha256', secret).update(rawBody).digest('hex')}`;
  return crypto.timingSafeEqual(Buffer.from(sigHeader), Buffer.from(expected));
}

On-Chain Referral Economy

Every referral automatically triggers a BTCPay Server pull-payment payout in LTC. Auto-approved claims mean zero manual intervention for commission processing.

Connection Pool

MySQL2 connection pool (10 concurrent) with promise wrappers ensures high-throughput game event writes without connection exhaustion under load.

Webhook Security

All BTCPay Server webhooks are verified with HMAC-SHA256 and timingSafeEqual to prevent timing attacks on signature validation.

React Frontend

Vite-powered React app with village builder UI, real-time LTC balance display, referral code sharing, and leaderboard — all connected to the Node.js API.