The link of Betting Contract:https://github.com/laronlineworld/Voting-Betting-Smart-Contract/blob/main/Voting-Betting-Smart-Contract.sol
How to change the bet ether into token(BEP20)
function betOnCandidate(bytes32 candidate) public payable {
require(bettingActive);
require(msg.value >= 1 ether);
require(validCandidate(candidate));
betters.push(msg.sender);
bets[candidate][msg.sender] += msg.value;
}
And also the reward into token
/* Function to close voting and handle payout. Can only be called by the owner. */
function closeVoting() onlyOwner public returns (bool) {
require(bettingActive);
bytes32 winningCandidate = candidateList[getWinner()];
// getting list of winners and losers
// and the money lost by all losers
address[] memory winners;
uint256 numWinners = 0;
uint256 numLosers = 0;
uint256 surplus = 0;
for (uint x = 0; x < betters.length; x++) {
if (bets[winningCandidate][betters[x]] > 0) {
winners[numWinners++] = betters[x];
} else {
surplus += bets[winningCandidate][betters[x]];
numLosers++;
}
}
// keeping 10% as service fee and distribute rest among the winners
uint256 prize = surplus * 9 / 10;
// calculate prize per winner
prize = prize / numLosers;
// distribute the prize to the winners alongwith the money they bet in
for (x = 0; x < winners.length; x++) {
winners[x].transfer(prize + bets[winningCandidate][winners[x]]);
}
// Close the betting period
bettingActive = false;
return true;
}