0

I've had this occur a few times, where I create a smart contract and one of the functions works in ethfiddle but reverts in Mist. I realized that in the Mist wallet, when I run the functions that fail, the transaction says Transfer between accounts instead of Contract execution. I solved this previously by creating a bool user input. So they'd just check the box and then run the function. However, I want to figure out how to run a function without this. Here is the code for the working function/contract:

pragma solidity ^0.4.24;

contract MyContract {

    uint nonce = 1;

    struct Instructor {
        address adr;
        uint8[6] array;
        }

    uint counter = 100;

    mapping (uint => Instructor) instructors;

    function multipleBets(bool start) public payable {
        if (start) { // <- ^ BOOL!
            uint div = msg.value/(0.01 ether);
            while (div > 0) {
                for (uint8 z = 0; z < 5; z++) {
                    uint8 ran = uint8(random());
                    if (ran == instructors[nonce].array[0] || 
                        ran == instructors[nonce].array[1] || 
                        ran == instructors[nonce].array[2] ||
                        ran == instructors[nonce].array[3] ||
                        ran == instructors[nonce].array[4]) {
                        z = z-1;
                    } else {instructors[nonce].array[z] = ran;}
                }
                instructors[nonce].array[5] = uint8(random());
                div--;
                nonce++;
            }
        }
    }

    function random() private returns (uint) {
        counter++;
        return counter;
    }

    function getStuff(uint _nonce) public view returns(uint8[6]) {
        uint8[6] storage _array = instructors[_nonce].array;
        return _array;
    }

}

tx for working function

reverting/failing function/contract:

pragma solidity ^0.4.24;

contract MyContract {

    uint nonce = 1;

    struct Instructor {
        address adr;
        uint8[6] array;
        }

    uint counter = 100;

    mapping (uint => Instructor) instructors;

    function multipleBets() public payable {
                // NO BOOL^
        uint div = msg.value/(0.01 ether);
        while (div > 0) {
            for (uint8 z = 0; z < 5; z++) {
                uint8 ran = uint8(random());
                if (ran == instructors[nonce].array[0] || 
                    ran == instructors[nonce].array[1] || 
                    ran == instructors[nonce].array[2] ||
                    ran == instructors[nonce].array[3] ||
                    ran == instructors[nonce].array[4]) {
                    z = z-1;
                } else {instructors[nonce].array[z] = ran;}
            }
            instructors[nonce].array[5] = uint8(random());
            div--;
            nonce++;
        }
    }

    function random() private returns (uint) {
        counter++;
        return counter;
    }

    function getStuff(uint _nonce) public view returns(uint8[6]) {
        uint8[6] storage _array = instructors[_nonce].array;
        return _array;
    }

}

tx for reverting/failing function

as you can see, the only difference is that one uses a bool for user input. I am running this on the Rinkeby Testnet.

Thanks a ton!

Your Answer

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

Browse other questions tagged or ask your own question.