Wisdom of Crowd: Decentralized prediction market on lotionjs with tendermint blockchain

Peter Ma
Peter Ma
Sep 26, 2018 · 6 min read

Written by Peter Ma and Solomon Wu — September 25, 2018

So after a few month of hard work, we were finally able to build out out dApp, Wisdom of Crowd, Decentralized prediction market powered by lotionjs and tendermint. We are proud of share our open sourced dApp with the world. Our home page is located at http://www.wisdomofcrowd.org, and you can easily test out our prediction engine through http://www.wisdomofcrowd.org:3000/state


By the time of writing this post, blockchain has already become a common household names not just in tech community, but all over the world. I’d be 1,000,000th person writing about the history of Satoshi and Bitcoin which you can probably easily google the information. If you are reading this article and don’t know what blockchain is, we’d highly recommend you do some research and to catch up with the technology.

dApps or Decentralized Apps

Bitcoin was one of the first use cases for Blockchain, after it’s rise to fame, the market has been exploring and experimenting with other use cases. One of most famous use case have been CryptoKitties which allows user to hold collectibles rather than just common tokens. Other dApps have been integrated into government system ranging from election to keeping refugee identities.

In the world of more and more speculation, we believe a Decentralized Prediction Market will provide utility to users in the near future. Therefore we’ve created Wisdom Of Crowd, Decentralized prediction market on lotionjs with tendermint blockchain.

Decentralized vs Centralized Prediction Markets

A decentralized prediction market has the following benefits:

  • permissionless — allow anyone to create a topic to predict the outcome. Anyone could be a market creator.
  • no central point of failure — a centralized platform has a centralized point of failure.
  • no need to trust a party to hold and safe-guard the fund — a centralized platform could run-away with the fund
  • objective — a centralized platform could secretly bet on certain outcome. When the actual outcome is not in their favor, they might stop that particular market. A decentralized platform would be difficult to stop.
  • transparency — payments are all recorded on chain and can be examined by everyone. The platform cannot lie about payment or lack of payment.
  • censorship-resistance — a centralized platform could choose not to pay a certain people.
  • providing a rich history of immutable prediction data — the prediction data history cannot be manipulated. These data may be used to create better prediction in the future.


We have decided to run this system on Lotionjs/Tendermint because of the following:

We believe in the scalability vision of multiple application specific chains that can interoperate with each other.

Scalability is a tough problem for blockchain. Even if an underlying blockchain has a very large throughput, your app’s performance may still be crippled by the sudden popularity of CryptoKitties because both dapps are co-located on the same blockchain. This is why scalability by separation of application is an important factor.

Tendermint has finality

Our prediction market has multiple phases that are delinated by “time” (by “time”, I actually mean “block height”). When we are calculating the final distribution of prediciton market, we have to make sure the voting data in the previous blocks will not change, otherwise the distribution calculation would be incorrect. With finality, separating the phase by block height is trivial. In system without finality, blocks are not final. The last block’s data could change (a term that is sometimes called branching). The blocks just become more and more sure that it reaches a point that it is theoretically impossible for the block data to change. In system without finality, separating phases by block could be a problem. We will need to pad each phase with several blocks of gap to make sure the last phase does not change.

Lotion is extremely developer friendly

Lotion is amazingly “smooth” to work with. It is the easiest to setup a new test chain and allow developers to dive right in.

Wisdom of Crowd — Decentralized Prediction Market

Through this decentralized prediction market we’ve divided them up to 5 different phases

  1. open new market
  2. allow bet
  3. someone bets (record them)
  4. market closes (by time)

condition to enter phase: time

  1. get data from oracle
  2. determine the result and record it

condition to end phase: time

condition to enter phase: time, someone triggers it

  1. someone stake their coin and challenges

condition to end phase: time

condition to enter phase: challenge phase completed

  1. anyone can stake their coin and vote

condition to end phase: time

condition to enter phase: time

  1. determine the final outcome

condition to end phase: when everything in the phase is executed

These 5 phases allows users to easily and securely allow user to open market, place bets, as well as to challenge and vote when they believe oracle is not giving the correct results.

The time of the phase is indicated by block height. since we have finality, the phase start and stop block can be next to each other. In other ledger that lacks finality, we should reserve more time (several blocks) between each phase.

Open Sourced

Our platform is readily open sourced, feel free to check it out at https://github.com/swswsw/predictionmkt


node app.js

test invocation:

it is possible to do test invocation using curl. however, you will need to supply signature yourself.
it is recommended to use test/testCommon.js complexSendTx(), which will handle the signature, public key (pubkey), and sequence.

for example of test invocation, please see test/testIntegrate2.js

if you need to send a transaction manually, you need to supply from.pubkey, from.signature, from.sequence, and to. the format is as follows.

curl -X POST http://localhost:3000/txs -d ‘{“type”: “verifySig”, “from”: { “pubkey”: “rewlkjrlw”, “signature”: “rewlkajrlewk”, “sequence”: 0 }, “to”: {} }’

all of the tx will need from and to. however, for brevity purpose, they are omitted in the following calls:

curl -X POST http://localhost:3000/txs -d ‘{“type”: “start”, “marketId”: “market2”, “startInfo”: …}’

example startInfo:

curl -X POST http://localhost:3000/txs -d ‘{“type”: “bet”, “marketId”: “market2”, “outcome”: 1, “amount”: 10, “user”: “5wvwWgKP3Qfw1akQoXWg4NtKmzx5v4dTj”}’

curl -X POST http://localhost:3000/txs -d ‘{“type”: “bet”, “marketId”: “market2”, “outcome”: 2, “amount”: 10, “user”: “9x2yu6AzwWphm3j6h9pTaJh63h5ioG8RL”}’

curl -X POST http://localhost:3000/txs -d ‘{“type”: “oracle”, “marketId”: “market2”, “outcome”: 2}’

curl -X POST http://localhost:3000/txs -d ‘{“type”: “challenge”, “marketId”: “market2”, “user”: “5wvwWgKP3Qfw1akQoXWg4NtKmzx5v4dTj”, “amount”: 100}’

curl -X POST http://localhost:3000/txs -d ‘{“type”: “vote”, “marketId”: “market2”, “user”: “5wvwWgKP3Qfw1akQoXWg4NtKmzx5v4dTj”, “amount”: 1000, “outcome”: 1}’

curl -X POST http://localhost:3000/txs -d ‘{“type”: “vote”, “marketId”: “market2”, “user”: “9x2yu6AzwWphm3j6h9pTaJh63h5ioG8RL”, “amount”: 10, “outcome”: 2}’

curl -X POST http://localhost:3000/txs -d ‘{“type”: “vote”, “marketId”: “market2”, “user”: “9x2yu6AzwWphm3j6h9pTaJh63h5ioG8RL”, “amount”: 1000, “outcome”: 1}’

curl -X POST http://localhost:3000/txs -d ‘{“type”: “distribute”, “marketId”: “market2”}’

for example of sending token to another address, see test/testSend.js for example of tx format.

The prediction is yours

With our engine, we will be launching our web app very soon for those who are interested. We’d first start with private market such as event hosts or sports bar, once those smaller events proves to be stable we will be moving towards world events and American politics.

For those who wants to use our service please visit us at http://www.wisdomofcrowd.org

Wisdom of Crowd

Wisdom of Crowd

Decentralized prediction market

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store