Sehr sehr neu dazu.
Sie senden 1 Ether an den Vertrag:
Warum wird der Vertrag nicht ausgeführt?
Danke
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
bedeutet, dass 1 wei gesendet wird. Sie müssen es durch ersetzen msg.value == 1 ether
.
Der Gasmangel-Fehler ist wahrscheinlich das Ergebnis einer falschen Gaszufuhr require()
, vorausgesetzt, Sie liefern eine angemessene Gasmenge.
Auch müssen Sie my_length == 0;
zu ändernmy_length = 0;