// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0;
contract lottery{
address public manager;
address payable[] public players;
constructor(){
manager = msg.sender;
}
function allreadyEntered() view private returns (bool){
for (uint i=0; i>players.length; i++){
if (players[i]==msg.sender)
return true;
}
return false;
}
function enter() payable public {
require(msg.sender != manager,"The Manager cannot enter.");
require(allreadyEntered() == false, "The Player is Already Entered");
require(msg.value >= 1 ether, "The Wallet Balance is Low for Enter");
}
function random() private view returns (uint) {
return uint(sha256(abi.encodePacked(block.prevrandao, block.number, players)));
}
function picWainner() public {
require(msg.sender == manager, "Only Manager can Select The Winner");
uint index = random() % players.length;
address contractAddress = address(this);
players[index].transfer(contractAddress.balance);
players = new address payable[](0);
}
function getPlayer() view public returns (address payable[] memory){
return players;
}
}
-
Could be the spelling of your "picWainner" function.– FOURBBBBCommented Mar 30 at 14:47
-
1can you specify the error or at least mention the expected and current behaviour?– Zartaj AfserCommented Mar 30 at 15:33
1 Answer
I believe you are trying to pull getPlayers to the front-end from your local copy instance.
- If this is the case, I'd recommend you compile and deploy the contract on remix.ethereum.org
Once you have compiled and deployed it with Remix.
Change your lottery.js file or the file that you are using to connect your deployed address as well as your contract ABI.
Use this page to copy the ABI from it after a successful compile. Remember to compile with your test Metamask account
Then deploy your contract and copy the deployed address from it, this address should be used in the file you have the ABI file i.e. lottery.js file. Clicking on the Compilation Details will also give you the ABI, and several other information
- After this, run your application front-end(I presume React) and your get players should now appear.
Similar Project on Github -> github.com/Ndhlovu1/ethereum-react-lottery