1

Let me give scenario, let's say: There are 2 types of playable characters

  • Chickens (90% chance to mint)
  • Foxes (10% chance to mint)

and total supply is 15,000 units :

  • 13,500 chickens
  • 1,500 foxes

How to determine whether a Chicken or a Fox is minted?

I guess random number generator is good for this but random function is not supported anymore by ink!

2
  • What do you mean? how to randomly pick one of the 2 options?
    – Alex Bean
    Jul 17 at 11:00
  • so total supply is 15,000 and We wan't mint function generate random number to determine whether a Chicken or a Fox is minted. @AlexBean
    – Ganesh11
    Jul 17 at 17:38

1 Answer 1

1

Generate the random number between 1 and 15,000 based on a future block hash then if the random number is in the first 10% of values in that range then you could determine that a Chicken was minted, whereas if the random number is in the remaining 90% of that range then you could determine that a Fox was minted.

5
  • how to get block_hash in ink! smart contract @Luke Schoen? There is not function to get block has here
    – Ganesh11
    Jul 19 at 10:38
  • i've highlight the only solution i can think of for ink! that should work at the moment here github.com/paritytech/ink/issues/1849#issuecomment-1641098345, which involves having your ink! contract perform a cross-contract call to a Solidity contract that simply returns the relevant block hash since that function is supported in Solidity, for example run blockhash(blockNumber - 1); to get the previous block hash with Solidity. but that would only work on a chain that supports both Wasm and EVM contracts like Astar, since whilst cross-contract calls are supported. Jul 20 at 0:59
  • i've already written some code to generate a random number between 1 and 20 based on a future block hash here in 'rand-future' example github.com/ltfschoen/XCMTemplate/pull/23/…, but i'm manually providing the block hash as argument block_hash_entropy to function set_block_for_entropy_for_market_id, to generate the random number for a guessing game that started earlier. next step is for that ink! contract to perform a cross-contract call to a Solidity contract that simply returns the current block hash Jul 20 at 1:03
  • also see substrate.stackexchange.com/a/9325/83 Jul 20 at 1:05
  • FYI, here's my PR that uses cross-contact XVM to call from ink! to Solidity to get the block hash github.com/ltfschoen/XCMTemplate/pull/24/… Jul 21 at 14:33

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.