I have a smart contract running on BSC test net. Mainly the contract has 10 tokens, which are bought from random addresses. Once all of the tokens are bought, the contract will select one address and send the balance received to that one address excluding the gas fees. To make sure that there is enough gas, I'm sending only 80% of the balance received. The amount receive is at least 0.01BNB per transfer resulting in 0.1BNB minimum which should cover any fees.
address payable winner;
event endContract(address indexed winner);
uint256 private ticketCount;
function endContract() private {
require(ticketCount == MAX_TICKETS, "All tickets must be sold to select a winner");
uint256 winnerTicketId = random() % MAX_TICKETS + 1;
winner = ticketOwners[winnerTicketId]; //The value of the winner is selected correct
//transfer only 80% of the pot
uint256 transferAmount = (totalPot*80)/100;
winner.transfer(transferAmount);
emit endContract(winner);
}
The value of the winner is selected correctly. The value of the contract balance (totalPot) is also displayed correctly.
Is there any specific function other than transfer to issue a transfer to a selected address?
I've been going through this for a day now and could not figure it out. Contract address - 0xb39E6A3499DFA04a3eD5ed39ac9F57CF44E321fA
Thanks.
endContract
called? Why are you using the same name for a function and an event?