1

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

1

@Chris,

I took your Solidity code and tried out the same on Rinkeyby test network and it works perfectly for me as expected.

Please cross check : - that you have enough balance to execute each transaction (function call), you can get test Ethers to use on rinkeby test network from here.

  • allow couple of seconds for each transaction to be validated by miners and then refresh the function call, you should see the changed state.
  • for my ropsten I have 10 Eth and rinkeby I have 18.75. Whenever run the 'Start The Lotto' (on either network) I recieve Warning! Error encountered during contract execution [Reverted] without fail. link. Can I see your contract address? – Christopher Cruttenden Mar 1 at 22:34
0

So after a lot of recoding and freaking out... haha... I noticed something peculiar. When I executed (order 66 ha) PickYourNumbers() in the "latest transactions" (bottom of mist wallet) it said Contract execution. But when I executed StartTheLotto() it said Transfer between accounts.

I then decided get user input for the second function, so instead of StartTheLotto() I did StartTheLotto(int8 asdf) and adjusted accordingly. Now, for some weird reason the function works and displays Contract execution. I would love it if someone could elaborate better than I could so I could have the why and not just the how.

new code:

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;
    uint addr = address(this).balance;
    uint nonce = 1;
    uint startTime = now;
    int8 fdsa;              // ADDED THIS VAR TO USE ASDF USR INPUT

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

                   //ADDED USR INPUT HERE
    function StartTheLotto(int8 asdf) public returns (uint[6] memory) {
        fdsa = asdf; // USESD IT SO WOULDN'T THROW ERROR
        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;
    }

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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