Muy muy nuevo en esto.
Envías 1 ether al contrato:
¿Por qué no se ejecuta el contrato?
Gracias
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;
gamblers[random].transfer(5);
my_length == 0;
}
}
}
msg.value == 1
significa que se envía 1 wei. Necesitas reemplazarlo con msg.value == 1 ether
.
El error de falta de gas es probablemente el resultado de un error require()
, dado que está suministrando una cantidad razonable de gas.
También tienes que cambiar my_length == 0;
amy_length = 0;