polkamarkets-js 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +99 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,99 @@
1
+ ![alt tag](https://uploads-ssl.webflow.com/6001b8a9fb88852f468bf865/600f55bddbe2354c1e36e200_Dark.svg)
2
+
3
+ ## Introductions
4
+
5
+ `polkamarkets-js` is the Polkamarkets Javascript SDK to integrate Prediction Markets into any dapp.
6
+
7
+ ## Installation
8
+
9
+ Using [npm](https://www.npmjs.com/):
10
+
11
+ ```bash
12
+ npm install "polkamarkets-js" --save
13
+ ```
14
+
15
+ Using [yarn](https://yarnpkg.com/):
16
+
17
+ ```bash
18
+ yarn add polkamarkets-js
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ ### Initializing App
24
+
25
+ Polkamarkets uses [`bepro-js`](https://github.com/bepronetwork/bepro-js/tree/feature/prediction-markets) for the web3 EVM integration.
26
+
27
+ You'll need to provide a web3 RPC provider (e.g., Infura for Ethereum dapps)
28
+
29
+ ```javascript
30
+ import Polkamarkets from 'polkamarkets-js';
31
+
32
+ // Moonriver RPC
33
+ const web3Provider = 'https://rpc.moonriver.moonbeam.network';
34
+
35
+ // Starting application
36
+ const polkamarkets = new Polkamarkets(web3Provider);
37
+
38
+ // Connecting wallet
39
+ await polkamarkets.login();
40
+
41
+ // Fetching connected address
42
+ const balance = await polkamarkets.getAddress();
43
+
44
+ // Fetching address balance
45
+ const balance = await polkamarkets.getBalance();
46
+ ```
47
+
48
+ ### Prediction Markets
49
+
50
+ Once the library is initialized, it's ready to interact with prediction markets smart contracts.
51
+
52
+ ```javascript
53
+ const contractAddress = '0xDcBe79f74c98368141798eA0b7b979B9bA54b026';
54
+ polkamarkets.getPredictionMarketContract(contractAddress);
55
+ ```
56
+
57
+ Once initialized, you'll be able to interact with the smart contract.
58
+
59
+ - Prediction Market Smart Contract: [PredictionMarket.sol](https://github.com/bepronetwork/bepro-js/blob/feature/prediction-markets/contracts/PredictionMarket.sol)
60
+ - Prediction Market JS Integration: [PredictionMarketContract.js](https://github.com/bepronetwork/bepro-js/blob/feature/prediction-markets/src/models/PredictionMarketContract.js)
61
+
62
+ Here's a few call examples
63
+
64
+ ```javascript
65
+ const marketId = 1;
66
+ const outcomeId = 0;
67
+ const ethAmount = 0.1;
68
+
69
+ // Fetching Market Details
70
+ await polkamarkets.getMarketData(marketId);
71
+
72
+ // Buying Outcome Shares
73
+ const mintOutcomeSharesToBuy = await polkamarkets.calcBuyAmount(marketId, outcomeId, ethAmount)
74
+ await polkamarkets.buy(marketId, outcomeId, ethAmount, minOutcomeSharesToBuy);
75
+
76
+ // Selling Outcome Shares
77
+ const maxOutcomeSharesToSell = await polkamarkets.calcSellAmount(marketId, outcomeId, ethAmount)
78
+ await polkamarkets.buy(marketId, outcomeId, ethAmount, maxOutcomeSharesToSell);
79
+
80
+ // Claiming Winnings
81
+ await polkamarkets.claimWinnings(marketId);
82
+
83
+ // Fetching portfolio data
84
+ await polkamarkets.getPortfolio();
85
+ ```
86
+
87
+ ## Contribution
88
+
89
+ Contributions are welcomed but we ask to red existing code guidelines, specially the code format. Please review [Contributor guidelines][1]
90
+
91
+ ## License
92
+
93
+ [MIT](https://choosealicense.com/licenses/mit/)
94
+
95
+ ## Notes
96
+
97
+ 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
98
+
99
+ [1]: https://github.com/bepronetwork/bepro-js/blob/master/CONTRIBUTING.md
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polkamarkets-js",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Polkamarkets Javascript SDK",
5
5
  "engines": {
6
6
  "node": "^14.15.0"