// SPDX-License-Identifier: MIT
pragma solidity >=0.5.0 <0.9.0;
contract Lottery
{
address public manager;
address payable[] participants;
constructor() public
{
manager = msg.sender;
}
receive() external payable //error on this line
{
require(msg.value==1 ether);
participants.push(payable(msg.sender));
}
function getBalance() public view returns(uint)
{
require(msg.sender==manager);
return address(this).balance;
}
function randomG() public view returns(uint)
{
return uint(keccak256(abi.encodePacked(block.difficulty, block.timestamp, participants.length)));
}
function SelectWinner() public
{
uint r=randomG();
uint index= r % participants.length;
address payable winner;
winner = participants[index];
winner.transfer(getBalance());
}
}
Please identify what is the error with the recieve function.This is a smart contract for a lottery system where a random winner is selected and paid. I cannot receive ether from the participant s address. what is wrong with the function? Are there any alternatives for the same?