2

I want to use action context information, such as block hash code, to generate number as "random" numbers in smart contract.

But I can't find any interface to get block hash code.

2
  • If you are looking to generate random numbers in your smart contract, take a look at this discussion: eosio.stackexchange.com/questions/41/… Commented May 14, 2018 at 17:52
  • @JohnHaager thank you so much for the link, the discussion is really helpful!
    – ofo
    Commented May 16, 2018 at 9:43

1 Answer 1

1

Block information isn't directly available. These two functions provide information from a user-selected previous block:

int tapos_block_num(); int tapos_block_prefix();

There are a couple problems with relying on these:

  • They are from a block in the past
  • The person who created the transaction filled these by selecting a block and copying the values
1
  • Thank you! Now I can get the block number and then save to table. My App can fetch the block number and then get the subsequent 15 (or more) blocks' information. I have another quesiton: What's the meaning of block prefix? What's it for?
    – ofo
    Commented May 16, 2018 at 13:51

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.