Learn how to use the Polkamarkets Protocol to build your own prediction markets.
๐น Overview
Polkamarkets Protocol V1 is a suite of EVM smart contracts, web services, and a web app that allows anyone to create autonomous prediction markets.
Using all, or parts, of the code base, you can:
- Integrate prediction markets into your dApps using the Polkamarkets JS SDK
- Deploy your own decentralized prediction marketplaces using the entire code base
- Create custom prediction markets products using bits and pieces from our codebase
Polkamarkets Labs is happy to help you throughout your development process, from ideation to launch and beyond. You can join the Polkamarkets Discord server to interact with the team and other developers, reach out to the Polkamarkets Labs directly, or create a GitHub issue in any of the repositories linked below.
๐น Polkamarkets JS SDK
The easiest way to integrate prediction markets into your dApp is simply to use the Polkamarkets JS SDK. With the SDK, you can easily make calls to the protocol to integrate functionality into your dApp.
๐น Polkamarkets Smart Contracts
The Polkamarkets Protocol implements a series of Solidity smart contracts to allow users to create prediction markets, buy and sell outcome shares, resolve markets, and award achievement badges (as ERC-721 NFTs).
- PredictionMarket.sol is responsible for the core prediction markets logic
- RealitioERC20.sol is responsible for the crowd-sourced market resolution logic
- Achievements.sol is responsible for the achievements logic
- Migrations.sol and ERC20.sol are development utility contracts
All the smart contracts are available in the same repository at https://github.com/bepronetwork/bepro-js/tree/feature/prediction-markets. The README provides instructions on how to get up and running. You can deploy the contracts on any EVM-compatible blockchain, and you can customize the code to suit your use case if needed.
The codebase leverages the
bepro-js
framework, OpenZeppelin
and Truffle
for ease of development.๐น Polkamarkets Web App
To allow end-users to interact with the smart contract, youโll probably want to use a web application.
The Polkamarkets web application is a front-end application built with React. You can use it as-is, or you can tweak it to suit your specific needs, be them aesthetic or functional.
The Web App expects to be able to interact with contracts that are already deployed as well as the Polkamarkets API.
๐น Polkamarkets API
For architectural and performance reasons, the Web App leverages a REST API.
You can build your own REST API from scratch, or use the Polkamarkets API code base as-is. Itโs built with Ruby on Rails.
Some functionality is very specific to how we implemented the application and relies on third-party services. You can choose to use everything as-is or to customize it to your own needs.
๐น Data Indexing API
While technically possible, directly querying EVM blockchains is not always a reliable approach.
For this reason, we created a Nodejs-based data indexing service that provides blockchain data through a REST API. We deploy one instance of the service per supported blockchain, and other developers have done the same.
This data caching API does RPC queries to blockchain nodes to gather event and contract data, either directly or through third-parties (for which you may need an API key and or paid plan API). You could, for example, query nodes that youโre running yourself through this implementation.