Custom Bitshares Airdrop Spotlight #005: Rewarding referrers by most referrals

in #bitshares4 months ago

Custom airdrop spotlight #005 - Referrers and referrals airdrop distributions

Time for another custom airdrop spotlight! Recent spotlights have focused on asset holders, governance objects and fees, now we're going to get into how to reward Bitshares blockchain accounts with an airdrop for their participation in the decentralized referral mechanism!

Why might you want to do such an airdrop?

There's multiple reasons you may/should consider airdropping Bitshares blockchain assets onto referral system participants; here's some to think about:

  • Encourage greater participation in the referral mechanism
  • Encourage improved referral ROI
    • By airdropping onto those who referred the top x asset holders, referrers may seek out better/larger referral targets.
  • Rewarding referrals without requiring referred account fee expenditure
    • More rewards up front and over time than solely core tokens.
  • Encourage users to upgrade to life time membership
    • Contributes fees to the reserve pool
    • By upgrading they become their own referrer and so qualify for referrer airdrop

Alright, let's get to the code!

We'll be importing a list of BTS asset holders, generated using the airdrop_tool/src/scripts/fetchAssetHolders.js script, as a prerequisite for the following code: (view file on github)

const fs = require('fs');
const inputUsers = require('./fetchedData/assetHolders.json'); // [{"name":"accountName","account_id":"1.2.x","amount":"12345"}]

const { getObjects } = require('./lib/directQueries');

const getUserReferralQty = async (accountName) => {
  console.log(`Fetching refferral qty for ${accountName}`);
  let referralQty;
  try {
    referralQty = await fetch(`https://api.bitshares.ws/openexplorer/referrer_count?account_id=${accountName}`);
  } catch (error) {
    console.log(error);
    return null;
  }

  const responseJSON = await referralQty.json();

  return responseJSON ?? null;
};

const writeToFile = (fileName, data) => {
  console.log(`Writing to ${fileName}`);
  fs.writeFileSync(fileName, JSON.stringify(data, null, 4));
};

const main = async () => {
  const retrievedReferralQtyData = [];
  for (let i = 0; i < inputUsers.slice(0, 10).length; i++) {
    const currentUser = inputUsers[i];
    let referralQty;
    try {
      referralQty = await getUserReferralQty(currentUser.name);
    } catch (error) {
      console.log(error);
      continue;
    }

    if (!referralQty) {
      continue;
    }

    retrievedReferralQtyData.push({
      id: currentUser.account_id,
      name: currentUser.name,
      qty: 1,
      value: referralQty
    });
  }

  writeToFile(
    './airdrops/asset_holder_referral_quantities.json',
    retrievedReferralQtyData.sort((a, b) => b.value - a.value)
  );

  const userIDs = inputUsers.slice(0, 10).map((user) => user.account_id);

  let retrievedUserObjects;
  try {
    retrievedUserObjects = await getObjects("wss://node.xbts.io/ws", "bitshares", userIDs);
  } catch (error) {
    console.log({ error, location: "getObjects", userIDs });
  }

  if (!retrievedUserObjects) {
    return;
  }

  const accountReferralAccounts = retrievedUserObjects.map((user) => user.referrer);
  const tallyReferralAccounts = (referralAccounts) => {
    const tally = {};
    referralAccounts.forEach((account) => {
      tally[account] = (tally[account] || 0) + 1;
    });
    return tally;
  };

  const referralAccountTally = tallyReferralAccounts(accountReferralAccounts);
  const referralAirdrop = Object.entries(referralAccountTally)
    .map(([account, qty]) => ({
      id: account,
      qty: 1,
      value: qty
    }));

  writeToFile(
    './airdrops/referrers_of_asset_holders.json',
    referralAirdrop.sort((a, b) => b.value - a.value)
  );

  // exit script
  process.exit(0);
};

main();

This script creates the following output from a slice of 10 top BTS asset holders:

  • ./airdrops/asset_holder_referral_quantities.json

This fetches the quantity of users referred by the top BTS asset holders, such as:

[
    {
        "id": "1.2.31074",
        "name": "abc.btsbots",
        "qty": 1,
        "value": 1
    }
]
  • ./airdrops/referrers_of_asset_holders.json

This fetches who referred the top asset holders:

[
    {
        "id": "1.2.96393",
        "qty": 1,
        "value": 3
    },
    {
        "id": "1.2.450921",
        "qty": 1,
        "value": 2
    },
    {
        "id": "1.2.223001",
        "qty": 1,
        "value": 1
    },
    {
        "id": "1.2.685874",
        "qty": 1,
        "value": 1
    },
    {
        "id": "1.2.31074",
        "qty": 1,
        "value": 1
    },
    {
        "id": "1.2.1686016",
        "qty": 1,
        "value": 1
    },
    {
        "id": "1.2.20067",
        "qty": 1,
        "value": 1
    }
]

These JSON output files can be imported in the custom airdrop section of the Bitshares Airdrop Tool, and broadcast to the Bitshares blockchain via the Bitshares BEET multiwallet:

And finally, the airdrop card prompting you to broadcast the airdrop transaction onto the Bitshares blockchain via the BEET multiwallet:

image.png

Once you've broadcast the airdrop via the Beet multiwallet, you'll have an optional receipt like the following for your airdrop:

image.png


These developments were brought to you by the NFTEA Gallery.
Consider collecting an NFTEA NFT to support continued Bitshares developments.

Don't have a Bitshares account? Make one today!

Coin Marketplace

STEEM 0.26
TRX 0.10
JST 0.031
BTC 41760.03
ETH 2240.72
USDT 1.00
SBD 5.14