Simple & provably fair Ethereum gambling Contract on Substrate blockchain.

Purnima Behera
2 min readApr 21, 2021

Two things have happened simultaneously one eth gas price has gone sky rocket and the polka dot ecosystem has ben going up up and up. Now the demand for running Ethereum smart contracts and Dapps on Substrate-based blockchains is high.

The ParaState (and Second State) team has done a wonderful job they have developed software that enables Ethereum smart contracts on Substrate blockchains.It supports smart contracts written in Solidity and other WebAssembly-compatible languages and supports both polkadot.js and web3.js based web application front-ends.

Here i will deploy a popular fair Ethereum gambling Contract (dice2.win)(https://github.com/dice2-win) to the ParaState testnet.

With the web3 RPC, we can use the BUIDL online IDE, created by Second State, to create, deploy, and test Solidity smart contracts. Load BUIDL for ParaState in your browser.

http://buidl.secondstate.io/parastate

Lets know a bit about dice2.win

  1. dice2.win picks a secret random number and provides you with its hash.
  2. You send your bet in Ethereum transaction to our smart contract along with the hash from previous step.
  3. At this point dice2.win has already commited to a number, prior to you chosing an outcome.
  4. Once your transaction is confirmed by the network, the contract stores the hash and bet details.
  5. Our croupier bot “reveals” the number by sending a bet settling transaction.
  6. The contract accepts the transaction if and only if the hash of provided number is the same as the stored one.
  7. The contract mixes the number and block hash of the bet transaction to get a random number.
  8. The contract decides whether you won or lost and sends you the winning amount of Ether.

The video below shows how to create, compile, and deploy a sdice2.win smart contract to the ParaState testnet. It also demonstrates how to call functions on the deployed smart contract.

Here the web3 RPC and BUIDL IDE make the ParaState testnet very much like an Ethereum blockchain. The users use Ethereum addresses and wallets to sign and send transactions. Substrate is completely behind the scene to manage and store information on the blockchain.

thank you .

--

--