Script to Check Splinterlands Pack Openings Value by reazuliqbal

View this thread on steempeak.com
· @reazuliqbal ·
$27.91
Script to Check Splinterlands Pack Openings Value
<center>![carbon.png](https://cdn.steemitimages.com/DQmagR1xSS1mYLxr77vUN2LqB1JARTi5wVz3dKfKAZkjVzW/carbon.png)</center>

As Splinterlands Beta packs are running out, many players are buying and opening beta packs. I am one of them too. In recent times I have bought 300 beta packs to open them. I was keeping track of my openings value by checking the change of my deck value in Peakmonsters.

While talking to @joshman in SFR discord about his recent beta packs openings value, I though why not create a script that can check our recent pack openings and show us the total value, so why can get a clearer picture.

So, I coded it, tested against my openings. I was not impressed what  pulled using 100% legendary and gold potions. Realized you have to very lucky or be @zaku to pull something very awesome. 😉

Here is the script:

```
/* eslint-disable no-loop-func */
/* eslint-disable no-await-in-loop */
const axios = require('axios');

const callApi = async (endpoint) => {
  let result = [];

  try {
    const { data } = await axios.get(`https://steemmonsters.com/${endpoint}`);
    result = data;
  } catch (e) {
    console.log(e);
  }

  return result;
};

const callHistoryApi = async (player, fromBlock = -1, beforeBlock = null, limit = 250) => {
  let result = [];
  try {
    const params = {
      username: player,
      from_block: fromBlock,
      limit,
      types: 'sm_open_pack,open_pack,sm_open_all,open_all',
    };

    if (beforeBlock) params.before_block = beforeBlock;

    const query = await axios.get('https://api.steemmonsters.io/players/history', { params });

    result = query.data;
  } catch (e) {
    console.log(e.message);
  }

  return result;
};

(async () => {
  const player = 'reazuliqbal'; // Your steem username
  const edition = 1; // 0 = Alpha, 1 = Beta, 2 = Promo
  const packsOpened = 100; // Number of packs to check

  // Might not needed to edit below this line
  const cards = [];
  let packs = 0;
  let beforeBlock = null;

  const market = await callApi('market/for_sale_grouped');
  const settings = await callApi('settings');

  do {
    let history = await callHistoryApi(player, -1, beforeBlock);

    history = history
      .filter((h) => h.success)
      .map((h) => ({
        id: h.id,
        type: h.type,
        block: h.block_num,
        data: JSON.parse(h.data),
        ...JSON.parse(h.result),
      }));

    history.forEach((h) => {
      if (h.data.edition === edition && packs < packsOpened) {
        packs += (h.data.qty) ? h.data.qty : 1;

        cards.push(...h.cards);
      }

      beforeBlock = (h.block - 1);
    });
  } while (packs < packsOpened);

  let usdPrice = 0;
  let steemPrice = 0;
  let sbdPrice = 0;
  let decPrice = 0;

  cards.forEach((c) => {
    const marketPrice = market.find((m) => m.card_detail_id === c.card_detail_id
      && m.gold === c.gold
      && m.edition === c.edition);

    usdPrice += marketPrice.low_price;
    steemPrice += marketPrice.low_price / settings.steem_price;
    sbdPrice += marketPrice.low_price / settings.sbd_price;
    decPrice += marketPrice.low_price / settings.dec_price;
  });

  console.log('Packs Opened:', packs);
  console.log('Cards prices in:');
  console.log('\tUSD:', usdPrice.toFixed(3));
  console.log('\tSTEEM:', steemPrice.toFixed(3));
  console.log('\tSBD:', sbdPrice.toFixed(3));
  console.log('\tDEC:', decPrice.toFixed(3));
})();
```
Here is the [Gist](https://gist.github.com/CodeBull/563ba009a5d08b3c7865c607595096af).

To use the script you need to have Node JS installed and a bit knowledge about how to install a npm package.

- Download or copy paste the code to a JS file inside a folder. Make changes to line [#41-43](https://gist.github.com/CodeBull/563ba009a5d08b3c7865c607595096af#file-splinterlands-pack-openings-js-L41-L43) according to your needs.
- Install `axios` npm package using this command `npm i axios`. 
- Now command `node your_js_filename.js`

You'll get your results like this

<center>![Screenshot from 2019-10-05 11-03-59.png](https://cdn.steemitimages.com/DQmdQPyNGKpnibzYVoo1Hh66Si59k11gmZAY4ynPtnFA6Uj/Screenshot%20from%202019-10-05%2011-03-59.png)</center>

This script might have some limitations or the value shown might not be accurate. Please use at your own risk.

<sup>[Carbon](https://carbon.now.sh/) was used for the cover image. 5% post rewards goes to Steem DAO.</sup>
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 130 others
👎  , ,
properties (23)
post_id80,603,914
authorreazuliqbal
permlinkscript-to-check-splinterlands-pack-openings-value
categoryspt
json_metadata{"tags":["spt","battle","neoxian","palnet","steemace"],"users":["joshman","zaku"],"image":["https:\/\/cdn.steemitimages.com\/DQmagR1xSS1mYLxr77vUN2LqB1JARTi5wVz3dKfKAZkjVzW\/carbon.png","https:\/\/cdn.steemitimages.com\/DQmdQPyNGKpnibzYVoo1Hh66Si59k11gmZAY4ynPtnFA6Uj\/Screenshot%20from%202019-10-05%2011-03-59.png"],"links":["https:\/\/gist.github.com\/CodeBull\/563ba009a5d08b3c7865c607595096af","https:\/\/gist.github.com\/CodeBull\/563ba009a5d08b3c7865c607595096af#file-splinterlands-pack-openings-js-L41-L43","https:\/\/carbon.now.sh\/"],"app":"steemit\/0.1","format":"markdown"}
created2019-10-05 05:13:57
last_update2019-10-05 05:13:57
depth0
children11
net_rshares82,044,768,229,789
last_payout2019-10-12 05:13:57
cashout_time1969-12-31 23:59:59
total_payout_value13.735 SBD
curator_payout_value14.177 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length4,371
author_reputation53,978,675,295,884
root_title"Script to Check Splinterlands Pack Openings Value"
beneficiaries
0.
accountsteem.dao
weight500
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars0
author_curate_reward""
vote details (197)
@bdvoter ·
Excellent work, dude. Now I do not have to manually check each card's prices and put on to the spreadsheet. Keep up the good work. 👍

<sup>~ [BDVoter Team](https://bdvoter.com)</sup>
👍  
properties (23)
post_id80,604,090
authorbdvoter
permlinkpyvyxk
categoryspt
json_metadata{"links":["https:\/\/bdvoter.com"],"app":"steemit\/0.1"}
created2019-10-05 05:22:36
last_update2019-10-05 05:22:36
depth1
children1
net_rshares9,819,213,575
last_payout2019-10-12 05:22:36
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length182
author_reputation5,666,740,605,819
root_title"Script to Check Splinterlands Pack Openings Value"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)
@reazuliqbal ·
Glad that it would help. :)
👍  ,
properties (23)
post_id80,632,105
authorreazuliqbal
permlinkpyxvzn
categoryspt
json_metadata{"app":"steemit\/0.1"}
created2019-10-06 06:14:12
last_update2019-10-06 06:14:12
depth2
children0
net_rshares56,731,324,974
last_payout2019-10-13 06:14:12
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length27
author_reputation53,978,675,295,884
root_title"Script to Check Splinterlands Pack Openings Value"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (2)
@joshman ·
Nice work!
👍  ,
properties (23)
post_id80,605,261
authorjoshman
permlinkre-reazuliqbal-pyw2ix
categoryspt
json_metadata{"tags":["spt"],"app":"steempeak\/1.17.1"}
created2019-10-05 06:40:09
last_update2019-10-05 06:40:09
depth1
children1
net_rshares43,154,399,530
last_payout2019-10-12 06:40:09
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length10
author_reputation107,977,516,232,770
root_title"Script to Check Splinterlands Pack Openings Value"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (2)
@reazuliqbal ·
$0.02
properties (23)
post_id80,632,110
authorreazuliqbal
permlinkpyxw04
categoryspt
json_metadata{"app":"steemit\/0.1"}
created2019-10-06 06:14:27
last_update2019-10-06 06:14:27
depth2
children0
net_rshares134,992,472,769
last_payout2019-10-13 06:14:27
cashout_time1969-12-31 23:59:59
total_payout_value0.012 SBD
curator_payout_value0.012 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length7
author_reputation53,978,675,295,884
root_title"Script to Check Splinterlands Pack Openings Value"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (4)
@cryptorg ·
Pretty awesome tool to get the value of the packs instead of using excel or some other way to keep track of the cards and sum all of their value. Sharing is caring, so much apreciated to have this piece of code available for everybody to use.
properties (22)
post_id80,614,751
authorcryptorg
permlinkre-reazuliqbal-2019105t17377936z
categoryspt
json_metadata{"tags":["spt","battle","neoxian","palnet","steemace"],"app":"esteem\/2.2.0-surfer","format":"markdown+html","community":"esteem.app"}
created2019-10-05 14:37:09
last_update2019-10-05 14:37:09
depth1
children1
net_rshares0
last_payout2019-10-12 14:37:09
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length242
author_reputation8,576,958,985,908
root_title"Script to Check Splinterlands Pack Openings Value"
beneficiaries
0.
accountesteemapp
weight1,000
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@reazuliqbal ·
I am glad it would help and you liked it.
👍  ,
properties (23)
post_id80,632,098
authorreazuliqbal
permlinkpyxvye
categoryspt
json_metadata{"app":"steemit\/0.1"}
created2019-10-06 06:13:27
last_update2019-10-06 06:13:27
depth2
children0
net_rshares56,668,797,738
last_payout2019-10-13 06:13:27
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length41
author_reputation53,978,675,295,884
root_title"Script to Check Splinterlands Pack Openings Value"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (2)
@inertia ·
$0.05
The quick way:

```bash
git clone https://gist.github.com/563ba009a5d08b3c7865c607595096af.git
cd 563ba009a5d08b3c7865c607595096af
npm i axios
node splinterlands-pack-openings.js
```
👍  , , , ,
properties (23)
post_id80,619,086
authorinertia
permlinkpywx4t
categoryspt
json_metadata{"tags":["spt"],"app":"splintertalk\/0.1","canonical_url":"https:\/\/www.splintertalk.io\/@inertia\/pywx4t"}
created2019-10-05 17:41:18
last_update2019-10-05 17:41:18
depth1
children1
net_rshares262,734,993,134
last_payout2019-10-12 17:41:18
cashout_time1969-12-31 23:59:59
total_payout_value0.024 SBD
curator_payout_value0.024 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length182
author_reputation227,335,189,892,062
root_title"Script to Check Splinterlands Pack Openings Value"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (5)
@reazuliqbal ·
Thanks :)
👍  ,
properties (23)
post_id80,632,086
authorreazuliqbal
permlinkpyxvwp
categoryspt
json_metadata{"app":"steemit\/0.1"}
created2019-10-06 06:12:27
last_update2019-10-06 06:12:27
depth2
children0
net_rshares56,663,458,607
last_payout2019-10-13 06:12:27
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length9
author_reputation53,978,675,295,884
root_title"Script to Check Splinterlands Pack Openings Value"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (2)
@battlegames ·
nice tool!
properties (22)
post_id80,624,226
authorbattlegames
permlinkpyx8y2
categoryspt
json_metadata{"tags":["spt","battle"],"app":"battlegames\/0.1","canonical_url":"https:\/\/www.battlegames.io\/@battlegames\/pyx8y2"}
created2019-10-05 21:56:30
last_update2019-10-05 21:56:30
depth1
children1
net_rshares0
last_payout2019-10-12 21:56:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length10
author_reputation9,872,893,322,408
root_title"Script to Check Splinterlands Pack Openings Value"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@reazuliqbal ·
Thank :)
👍  ,
properties (23)
post_id80,632,089
authorreazuliqbal
permlinkpyxvx7
categoryspt
json_metadata{"app":"steemit\/0.1"}
created2019-10-06 06:12:42
last_update2019-10-06 06:12:42
depth2
children0
net_rshares56,665,515,266
last_payout2019-10-13 06:12:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length8
author_reputation53,978,675,295,884
root_title"Script to Check Splinterlands Pack Openings Value"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (2)
@pennsif ·
This post has been included in the latest edition of  [**The Steem News**](https://steemit.com/steem/@pennsif/the-steem-news-5-october-2019) - a compilation of the key news stories on the Steem blockchain.
👍  
properties (23)
post_id80,651,284
authorpennsif
permlinkpyz3w9
categoryspt
json_metadata{"links":["https:\/\/steemit.com\/steem\/@pennsif\/the-steem-news-5-october-2019"],"app":"steemit\/0.1"}
created2019-10-06 22:02:33
last_update2019-10-06 22:02:33
depth1
children0
net_rshares2,388,262,595
last_payout2019-10-13 22:02:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length205
author_reputation1,133,559,822,277,583
root_title"Script to Check Splinterlands Pack Openings Value"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)