User1 bet the hash of Block 999,000 that hash(block(999,000) = even

user2 bet the hash of Block 999,000 that hash(block(999,000) = odd

Both users pay/sign 1 BTC in a CoinJoin for that bet to a P2SH. The winner will win 1.99BTC and 0.01 BTC is the tx fee.

How to make the scripts that can perform such action?

  1. Script1 that perform the betting section.(that specify the criteria for redemption).

  2. Script2. Redeem script (based on the output of block 999,000) that transfers the fund to the winner new PubKey Hash.

2 Answers 2


You can't.

Bitcoin Scripts have no access to the block hash, and cannot determine if it is odd or even. You would need an external oracle for this.

  • would it be possible to do so in the future? cause all the data for oracle decision making will be available in the bitcoin blockchain.
    – Cisco Mmu
    Commented Aug 1, 2020 at 14:27
  • @CiscoMmu you would need to write code that does this (new OP codes), and then convince the vast majority of users running nodes to run your code (soft fork the network). If the benefit is just 'gambling on the blockchain', I kind of doubt users will be willing to change the protocol for it.
    – chytrik
    Commented Aug 1, 2020 at 20:45
  • ok TQ TQ! well, users kind of hard to be convinced.
    – Cisco Mmu
    Commented Aug 2, 2020 at 5:55

Discreet Log Contracts can solve this problem. I confirmed in a meeting today. To discuss implementation details please join slack channel where dlc and p2p derivatives are being discussed.

Reason: No access to block headers from script.

I was assuming miniscricpt might help with some workaround but it just makes it easier to write script and doesn't add anything extra in terms of functionality.


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.