Introducing Precognition
The application presented here addresses the currently uncovered Prediction Markets segment that is envisioned for in the original NEO White paper (Note: exchanges are a separate category). Precognition is a decentralized prediction market application running on the NEO Blockchain which allows people to speculate on future events using any NEP5Token. Through a combination of Event
and Oracle
smart contracts implementing different speculation and resolution algorithms, speculative events can be created by anyone and automatically resolved by the oracles on the blockchain in true decentralized fashion! Precognition implements 1 Event
smart contract using the parimutuel betting algorithm as well as a central oracle
smart contract. The Event
contract can work with any specified Oracle
contract through using Dynamic application calls. Similarly, the Central Oracle
contract can be used by Event
contracts implementing different speculation algorithms. A web interface with middleware is added to the solution for easy access, but the smart contracts can of course be used standalone.
While prediction markets are often associated with illegal betting schemes, there are many legal and useful approaches such as the state controlled China Sports Lottery and China Wellfare Lottery. The beauty of prediction markets is that the betting behaviour and price in such markets reflects all collective knowledge including secret knowledge some participants might have. History shows that prediction markets have been notoriously accurate in for example US presidential election forecasting. The concept can be applied for collecting expectancy information regarding any future event e.g. Movie box sales and determining marketing efforts.
Besides addressing an uncovered segment of the ecosystem, this first iteration serves as a lessons learned as well as a showcase project for others on how to interact with the blockchain using Python. Unlike many past submissions this project will not only open source the smart contracts but everything (Frontend, Backend, Middleware and all smart contracts). It is extensively documented in order to give insights into why an approach was chosen or how else it could be done.
What you can expect to learn
- Using neo-python-core to validate Blockchain key data.
- Using neo-python-rpc to query our own or public nodes for smart contract data on the blockchain.
- Querying the blockchain using a slightly modified neo-python as Blockchain middleware running the experimental RPC server.
- Building special transactions to interact with your smart contract and sending them to the blockchain.
- Listening and reacting to live smart contract notification events happening on the blockchain.
- Dynamically calling other smart contracts on the blockchain from your own smart contract.
Ecosystem contributions
The following developer ecosystem contributions have been made as driven by this project.
- NEO-VM issue report: [DynamicAppCall] GetCallingScriptHash can only be called from Main.
- neo-python issue report 1: JsonRpcApi input & output differs from C#
- neo-python issue report 2: New UserWallet throws TypeError: 'dict_values' object does not support indexing.
- neo-boa issue report: [DynamicAppCall] stack frame misalignment (workaround included).
- neo-python-rpc PR: seedlist updating + testcase fixes.
- Lessons learned writing Smart contracts with Python - See Appendix Lessons learned.
Disclaimer
The code presented in this project is NOT production ready. It has been is developed in a heavily time constrained period and decisions have been made for speed over security and reuseability. You'll see mixed code approaches for similar interactions with the sole purpose of showcasing, not because it was the best design decision. If you want to learn what I would do different next iteration then see Appendix - Next Iteration. Lastly, I'm not a front-end/web developer so bare with me :-)