0
pragma solidity ^0.8.0;

    uint256 private RandNonce = 0;
    function RandomNumber() public returns(uint256){
        uint256 rand = uint(keccak256(abi.encodePacked(block.timestamp,msg.sender,RandNonce))) % 100; 
        RandNonce++;
        return rand;
    }

I made this function in Remix and deployed well. But this function not working errorCode : transact to SimpleCoin.RandomNumber pending ...

what's wrong this function?

1 Answer 1

0

Might be that you have to wrap the function and the variable in a contract, so:

pragma solidity ^0.8.0;

    contract Random {
        uint256 private RandNonce = 0;

        function randomNumber() public returns(uint256){
            uint256 rand = uint(keccak256(abi.encodePacked(block.timestamp,msg.sender,RandNonce))) % 100; 
            RandNonce++;
            return rand;
        }
  }

The function itself looks like it should be callable as is.

1
  • Thanks for your advice. But I wrapped in a contract, just i left out in question. And I deployed again and execute function, it works... I modified nothing. Anyway Thanks for your effort:)
    – spear dark
    Commented Jul 13, 2022 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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