1.0.2 • Published 2 years ago

polkamarkets-js v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

alt tag

Introductions

polkamarkets-js is the Polkamarkets Javascript SDK to integrate Prediction Markets into any dapp.

Installation

Using npm:

npm install "polkamarkets-js" --save

Using yarn:

yarn add polkamarkets-js

Usage

Initializing App

Polkamarkets uses bepro-js for the web3 EVM integration.

You'll need to provide a web3 RPC provider (e.g., Infura for Ethereum dapps)

import Polkamarkets from 'polkamarkets-js';

// Moonriver RPC
const web3Provider = 'https://rpc.moonriver.moonbeam.network';

// Starting application
const polkamarkets = new Polkamarkets(web3Provider);

// Connecting wallet
await polkamarkets.login();

// Fetching connected address
const balance = await polkamarkets.getAddress();

// Fetching address balance
const balance = await polkamarkets.getBalance();

Prediction Markets

Once the library is initialized, it's ready to interact with prediction markets smart contracts.

const contractAddress = '0xDcBe79f74c98368141798eA0b7b979B9bA54b026';
polkamarkets.getPredictionMarketContract(contractAddress);

Once initialized, you'll be able to interact with the smart contract.

Here's a few call examples

const marketId = 1;
const outcomeId = 0;
const ethAmount = 0.1;

// Fetching Market Details
await polkamarkets.getMarketData(marketId);

// Buying Outcome Shares
const mintOutcomeSharesToBuy = await polkamarkets.calcBuyAmount(marketId, outcomeId, ethAmount)
await polkamarkets.buy(marketId, outcomeId, ethAmount, minOutcomeSharesToBuy);

// Selling Outcome Shares
const maxOutcomeSharesToSell = await polkamarkets.calcSellAmount(marketId, outcomeId, ethAmount)
await polkamarkets.sell(marketId, outcomeId, ethAmount, maxOutcomeSharesToSell);

// Claiming Winnings
await polkamarkets.claimWinnings(marketId);

// Fetching portfolio data
await polkamarkets.getPortfolio();

Contribution

Contributions are welcomed but we ask to red existing code guidelines, specially the code format. Please review Contributor guidelines

License

MIT

Notes

The usage of ETH in all methods or params means using the native currency of that blockchain, example BSC in Binance Chain would still be nominated as ETH