0
// 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;
    }



}
2
  • Could be the spelling of your "picWainner" function.
    – FOURBBBB
    Commented Mar 30 at 14:47
  • 1
    can you specify the error or at least mention the expected and current behaviour? Commented Mar 30 at 15:33

1 Answer 1

0

I believe you are trying to pull getPlayers to the front-end from your local copy instance.

  1. 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.

  1. Change your lottery.js file or the file that you are using to connect your deployed address as well as your contract ABI.

  2. Replace the ABI from the one in the Remix Deploy Page

  3. Use this page to copy the ABI from it after a successful compile. Remember to compile with your test Metamask account

  4. 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

enter image description here

  1. 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.