Very very new to this.

You send 1 ether to the contract:

  • It rejects it if it's not one ether exactly
  • If it is, adds the address to a mapping
  • If there are 5 mappings, it chooses an address at random and sends the 5 ethers, and resets the counter

Why will the contract not execute?


pragma solidity ^0.4.11;

contract BasicLottery {

        // A mapping to store ethereum addresses
            mapping(uint => address) public gamblers;

            uint public my_length; //*to keep track of the length.
            uint public random; //random number

            function BasicLottery(){
                my_length == 0;
        // function when someone sends an ether
        // stores the address, and if there are 5 participants, 
        // chooses a winner and gives the money

        function bet() payable {

        // If the bet is not 1 ether, send the
        // money back.
        require(msg.value == 1);

        my_length +=1;

        gamblers[my_length] = msg.sender;

        if (my_length == 5) {
            // pick a random number between 1 and 5
            random = uint(block.blockhash(block.number-1))%5 + 1;
            my_length == 0;


1 Answer 1


msg.value == 1 means 1 wei is sent. You need to replace it with msg.value == 1 ether.

The out of gas error is probably the result of the wrong require(), given you are supplying a reasonable amount of gas.

Also you need to change my_length == 0; to my_length = 0;

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.