3

I'm pretty new to Ethereum platform. I went through many tutorials and I understand that smart contracts contains back-end logic (link). Most of the examples I found implemented financial contracts, voting contracts etc. How can I implement complex back-end logic in solidity ?

Let's say I wanted to create a poker website. I think it's really hard to code all the logic using solidity contracts, since solidity doesn't seem to have much features. Another situation where I wanted to export all the data to excel or generate pdf / reports (I usually use python-flask), how can I implement such complex operations using solidity? Even if it's possible, doesn't it cost a lot of gas?

1 Answer 1

5

Ethereum is a very powerful platform, but the blockchain isn't a catchall for everything. A great solution to a poker website would be using state channels supported by the Ethereum blockchain. Funfair has a great article about state channels.

The basic summary is that you have players deposit their bet together into a smart contract and they trade signed states/moves with each other off-chain. If player A cheats, player B can take their signed state that cheated and submit it to the smart contract which would verify that they cheated (by running the move on the state they cheated on and verifying it was false) and release both players deposits to player B. If both players play a full game of honest poker (haha), then there will be a total of 3 transactions: the deposit of player A, the deposit of player B, and the submission of the final state by the winner.

5
  • 3
    To add to this great answer... Don't think of Solidity, or smart contracts, as the entire back-end. Sure it can be, in some use cases where it's useful and make sense. In case of your Poker example, a lot of the logic can be coded in your backend of choice. Having that backend, along with the client-side app, interact with the smart contracts (and state channels) for the handling of bets, recording the winner, sending of funds, etc.... Use the blockchain as it was intended - a digital ledger. Commented Jan 31, 2018 at 15:56
  • Would state channels actually work in decentralized poker? You need a trusted oracle (the dealer) to generate a random deck of cards. How could you do that using state channels? The linked blog hints how they injected randomness to be coming in Part 2, but Part 2 was never published Commented Jun 7, 2018 at 21:05
  • I have been looking into Funfair, and honestly, it seems like a scam. Commented Jun 7, 2018 at 21:37
  • @nickcarraway biparty random is easy with state channels by just doing a dual commit-reveal scheme. e.g. the deck is the 52 cards in order, and the next card is the outcome of the dual commit-reveal MOD 52. Repeat this and MOD the deck size each time, should work fine. As for funfair specifically, it's as much a scam as any casino is, which they all are to an extent, but at least funfair is putting out good developer literature and tech.
    – natewelch_
    Commented Jun 7, 2018 at 22:50
  • It would be nice if they made their code open-source Commented Jun 8, 2018 at 0:39

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.