total noob here.

But i like to learn.

I want to build a simple d20 dice rolling game with Solidity.

  • Is it possible?

  • if yes, what I need to know and use, to do it?

Thanks in advance.

2 Answers 2


Yes it's quite possible. The only challenge is the randomness. It is practically impossible to get 'true' randomness inside the blockchain (without special centralized outside help such as oracles).

Usually it's not necessary to generate really good randomness but sort of half-randomness is good enough. But if the stakes are very high (a big amount of ether for anyone who beats the system, for example) then half-randomness might be abused by miners.

If half-randomness is good enough, you just need one function (in your contract) which generates a random number and returns it to user. Something like:

function diceGame() public returns (uint) {
    uint randomNumber = ... // some way to generate a random number
    return randomNumber;

You can read more about randomness difficulties for example here: How can I securely generate a random number in my smart contract?


you can take a look at oracles to make external calls from smart contracts. http://www.oraclize.it/, keep in mind that there are several drawbacks on making external calls from a smart contract such as availability.

this video explains how to create a coin flip contract, calling the wolfram alpha oracle:


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.