Script to Check Splinterlands Pack Openings Value

Words
228
Reading
2 min
Listen
Play
7y

carbon.png

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@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@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.

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 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

Screenshot from 2019-10-05 11-03-59.png

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

Carbon was used for the cover image. 5% post rewards goes to Steem DAO.

Script to Check Splinterlands Pack Openings Value | Ecency