etherbingo-blitz / server.js
Jcrandall541's picture
app must be setup for master wallet ,owner of app takes 10 percent of total pots won
db7ca93 verified
```javascript
const express = require('express');
const cors = require('cors');
const { ethers } = require('ethers');
const app = express();
app.use(cors());
app.use(express.json());
// Configuration
const PORT = process.env.PORT || 3000;
const PROVIDER_URL = process.env.PROVIDER_URL || 'https://mainnet.infura.io/v3/YOUR_INFURA_KEY';
const MASTER_WALLET = process.env.MASTER_WALLET || '0xYourMasterWalletAddress'; // Replace with your master wallet
const COMMISSION_RATE = 0.1; // 10% commission
const provider = new ethers.providers.JsonRpcProvider(PROVIDER_URL);
// API Endpoints
app.post('/api/create-wallet', (req, res) => {
try {
const wallet = ethers.Wallet.createRandom();
res.json({
address: wallet.address,
privateKey: wallet.privateKey,
mnemonic: wallet.mnemonic.phrase
});
} catch (error) {
res.status(500).json({ error: 'Wallet creation failed' });
}
});
app.post('/api/check-balance', async (req, res) => {
try {
const { address } = req.body;
const balance = await provider.getBalance(address);
res.json({
balance: ethers.utils.formatEther(balance)
});
} catch (error) {
res.status(500).json({ error: 'Balance check failed' });
}
});
app.post('/api/distribute-winnings', async (req, res) => {
try {
const { winnerAddress, amount } = req.body;
// Calculate commission (10%)
const commission = amount * COMMISSION_RATE;
const winnerAmount = amount - commission;
// In production this would be handled by smart contract
res.json({
success: true,
winnerAmount: winnerAmount,
commission: commission,
masterWallet: MASTER_WALLET,
message: `Winner receives ${winnerAmount} ETH, ${commission} ETH sent to master wallet`
});
} catch (error) {
res.status(500).json({
success: false,
error: 'Distribution failed'
});
}
});
// Start server
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
```