//SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.5.0 < 0.9.0;
contract lottery{
bool public isLottery;
address manager;
address[] public participants;
constructor(){
manager=msg.sender;
}
modifier onlyManager(){
require(msg.sender==manager,"Only Manager can access this");
_;
}
function pay() public payable{
require(!isLottery, "Lottery has ended");
require(msg.value>=2 ether,"Donation must be greater than 0.99 ether");
participants.push(msg.sender);
}
function getBalance()public view returns(uint){
require(!isLottery, "Lottery has ended");
return address(this).balance;
}
function random() internal view returns(uint){
require(!isLottery, "Lottery has ended");
return uint(keccak256(abi.encodePacked(block.difficulty, block.timestamp, participants.length)));
}
function pickWinner()public onlyManager{
require(!isLottery, "Lottery has ended");
require(participants.length>3);
uint count=random();
uint winner=count%participants.length;
payable(participants[winner]).transfer(getBalance());
isLottery=true;
delete participants;
}
function startLottery()public onlyManager{
isLottery=false;
}
function showParticipants() public view returns(uint){
return participants.length;
}
}
This is a Lottery smart contract-
so whenever I use the executefunction to call the pickWinner function of my smart contract the contract always sends the contract balance to my account(owner account) and not to the actual winner’s account. Can anyone help me why this is happening.