This question has been asked before. however, those answers did not help me. (of course, I now can't find the "answer" atm) It said that Ropsten (what I was currently using) has fewer miners - or something to that extent, and therefore isn't the best to run smart contract. They recommended Rinkeby. I tried that, but it did not work either :( Currently, all functions work on Remix.
Here' some info about my Rinkeby and Ropsten:
I have two main functions, the first is PickYourNumbers()
which allows you to pick numbers, put them into an array, and then displays them on the contract with GetHash()
. This one works.
The second is StartTheLotto()
which calls the function random()
. This function generates... a random number. It calls this function 6 times, setting 6 vars in an array to different random numbers. Lastly, the array is displayed via lottoWinners()
.
I am guessing it is because I am having the contract/miners do too much? Do you have any recommendations?
pragma solidity ^0.4.24;
contract EthereumLottery {
uint[6] array;
uint[6] winners;
string warning = "please be sure to bet below 67 for the first 5 balls and 34 for the 6th";
address owner; // current owner of the contract
uint addr = address(this).balance;
uint nonce = 1;
uint startTime = now;
constructor() public {
owner = msg.sender;
}
function WARNING() public view returns (string memory) {
return warning;
}
function PickYourNumbers(uint8 firstBall, uint8 secondBall,
uint8 thirdBall, uint8 fourthBall,
uint8 fithBall, uint8 powerballllll) public {
if (firstBall <= 66) array[0] = firstBall;
if (secondBall <= 66) array[1] = secondBall;
if (thirdBall <= 66) array[2] = thirdBall;
if (fourthBall <= 66) array[3] = fourthBall;
if (fithBall <= 66) array[4] = fithBall;
if (powerballllll <= 66) array[5] = powerballllll;
}
function GetHash() public view returns (uint[6] memory) {
return array;
}
function StartTheLotto() public returns (uint[6] memory) {
nonce++;
winners[0] = random();
nonce++;
winners[1] = random();
nonce++;
winners[2] = random();
nonce++;
winners[3] = random();
nonce++;
winners[4] = random();
nonce++;
winners[5] = random();
}
function lottoWinners() public view returns (uint[6] memory) {
return winners;
}
function random() private view returns(uint) {
uint interval = now - startTime;
bytes32 randomNum = keccak256(abi.encodePacked(interval + nonce + tx.gasprice + addr));
uint number;
for(uint i=0;i<randomNum.length;i++){
number = number + uint(randomNum[i])*(2**(8*(randomNum.length-(i+1))));
}
return number % 67;
}
}
edit:
Rinkeby DAPP Addr: 0x75AB85fB72Ba93c9a9dF23E6FC775b58Dc7f050B
Ropsten DAPP Addr: 0x8bea60c97DC6BD955a614C58e5D0A0fBD12a8593
StartTheLotto()
I, without fail, receive Warning! Error encountered during contract execution - even with 10+ Ether