10

by this question I mean when we try to develop a gambling game contract we need some random input, can we just use the nonce data from some certain blocks? (I just start learning blockchain, I'm from China, there may be some language problems about my expression)

1 Answer 1

11

The nonce data is not available within the contract. The variables available within the contract code (from http://solidity.readthedocs.org/en/latest/miscellaneous.html#global-variables) are:

Global Variables

  • block.coinbase (address): current block miner’s address

  • block.difficulty (uint): current block difficulty

  • block.gaslimit (uint): current block gaslimit

  • block.number (uint): current block number

  • block.blockhash (function(uint) returns (bytes32)): hash of the given block - only works for 256 most recent blocks

  • block.timestamp (uint): current block timestamp

  • msg.data (bytes): complete calldata

  • msg.gas (uint): remaining gas

  • msg.sender (address): sender of the message (current call)

  • msg.value (uint): number of wei sent with the message

  • now (uint): current block timestamp (alias for block.timestamp)

  • tx.gasprice (uint): gas price of the transaction

  • tx.origin (address): sender of the transaction (full call chain)

  • sha3(...) returns (bytes32): compute the Ethereum-SHA3 hash of the (tightly packed) arguments

  • sha256(...) returns (bytes32): compute the SHA256 hash of the (tightly packed) arguments

  • ripemd160(...) returns (bytes20): compute RIPEMD of 256 the (tightly packed) arguments

  • ecrecover(bytes32, uint8, bytes32, bytes32) returns (address): recover public key from elliptic curve signature

  • addmod(uint x, uint y, uint k) returns (uint): compute (x + y) % k where the addition is performed with arbitrary precision and does not wrap around at 2**256.

  • mulmod(uint x, uint y, uint k) returns (uint): compute (x * y) % k where the multiplication is performed with arbitrary precision and does not wrap around at 2**256.

  • this (current contract’s type): the current contract, explicitly convertible to address

  • super: the contract one level higher in the inheritance hierarchy

  • selfdestruct(address): destroy the current contract, sending its funds to the given address

  • .balance: balance of the address in Wei
  • .send(uint256) returns (bool): send given amount of Wei to address, returns false on failure.

See the following if you are interested in generating (pseudo) random numbers:

2
  • if the miner's address is available, can we use that as a random input for I think that the miner of the block which contains certain gambling game transactions can not be known in advance?
    – Wang
    Apr 7, 2016 at 5:14
  • There is currently a 35.2% chance that the miners address with be dwarf_1's address etherchain.org/account/… . See etherchain.org/statistics/miners for the miner hashrate breakdown. You could use the miner's address to combine with other random input. See the second link if you want a reasonable random number generator. Apr 7, 2016 at 5:52

Your Answer

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

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