Hive Rewards SDK [Open-Source]

By crypto-shots on 4/28/2025

image.png

image.png

AI image generated starting from a screenshot of our game

npm hiverewards is out on @cryptoshots.nft's GitHub as an Open Source library!

https://github.com/Crypto-Shots/Hive-Earnings

  A new npm library designed to make it easier for both end users and developers to track HIVE-based earnings and reliably interact with the Hive ecosystem APIs for different purposes.


  • Have you ever wondered how much you earned from a Hive game or project in the past day/week/month/year?

  • Have you spent days/months wiring up a Hive app just to later find out that it's misbehaving because of a node issue?

  Hive Rewards is here to simplify your life. With a very little coding experience you can now execute some queries to find out your daily/weekly/monthly earnings.

Run such searches in your HTML page, directly in a terminal, or in your NodeJS scripts/backend.


npm hiverewards takes care of all the plumbing under the hood:

💰 Automatic price lookups and $ conversions, so you always know the dollar value you sent/received in any specific time range. 👨‍🔧 Retry mechanisms, node switching, smart caching and exponential back-off - meaning for example no surprises when a node hiccups. 🏥 Health checks to ensure the node is available before trying to fetch your data.


  Hive Rewards offers two SDKs out of the box:

  1. Hive Earnings SDK
    • Quickly compute how much HIVE and Hive-Engine tokens each target user has sent or received over any time window (hours, days, weeks, or months).
    • Handy insights for project owners/maintainers: monitor token distributions for marketing campaigns and/or manage your tokenomics with confidence.
    • Rather than (or on top of) storing user data in a database that you maintain, hiverewards allows you to pull player earnings straight from the Hive and Hive-Engine blockchains. No centralized ledger required. Or run it alongside your existing system as an audit tool, comparing your database reward records against the on-chain data to spot any discrepancies or anomalies.  
  2. Hive & Hive-Engine API wrappers with automatic node switching
    • Forget manually configuring endpoints or handling flaky RPC calls — our methods like hiveApiCall() and hiveEngineApiCall() will automatically and gracefully rotate and retry using other healthy nodes when one fails.
    • Extendable to any sidechain — the same pattern applies whether you’re talking to Hive Engine today or a brand-new chain tomorrow.



**Project Readme**

  📑 CONTENTS


- 😺 **[Peakd’s Beacon Wrapper](#peakds-beacon-wrapper)**  and  **[Hive / HiveEngine API Wrappers](#peakds-beacon-wrapper)**   - 😺 **[Usage in Crypto Shots](#usage-in-crypto-shots)**

Hive Rewards

An SDK for Node.js and the browser, and a command‑line tool to scan HIVE and Hive‑Engine token transfers:

  • Inbound — sum HIVE & tokens and USD value received by specified accounts, tracking specific sender accounts.
  • Outbound — map all recipients, tokens and USD values sent by a given sender.

Usage - NodeJS and Browser

import { hiveRewards } from 'hiverewards';

const analyzer = await hiveRewards({ verbose: true });

const inbound = await analyzer.inbounds({
  receivers: ['zillionz', 'obifenom'],
  hiveSenders: { PVP_HIVE: 'cryptoshots.tips' },
  tokenSenders: { PVP_TOKENS: 'cryptoshots.tips' },
  hours: 2,
});
console.log(inbound);

const outbound = await analyzer.outbounds({
  senders: ['cryptoshots.tips', 'karina.gpt'],
  ignoredReceivers: ['keychain.swap'],
  days: 1,
});
console.log(outbound);

Self-hosted bundle

A bundled build can be generated with Webpack:

  1. Clone the project

  2. Build it with

npm run build:web        # outputs dist/hiverewards.bundle.js
  1. Host the generated dist folder on your server
  2. Import it in your frontend and use it this way:
<script src="dist/hiverewards.bundle.js"></script>
<script>
  (async () => {
    const analyzer = await window.HiveRewards.hiveRewards();
    const result = await analyzer.inbounds({
      receivers: ['obifenom'],
      hiveSenders: { PVP_GAME_REWARDS: 'cryptoshots.tips' },
      days: 7,
    });
    console.log(result);
  })();
</script>

Usage - CLI

git clone <repo>
cd <repo>
npm install
npm start -- --inbound obifenom zillionz --from pvpRewards=cryptoshots.tips pveRewards=cryptoshotsdoom --hours 24
Image from post
npm start -- --outbound cryptoshots.tips karina.gpt --days 1
Image from post

Note: append --verbose for verbose logging


Configuration

Env var Default
HIVE_PRICE_URL https://api.coingecko.com/api/v3/simple/price?ids=hive&vs_currencies=usd

You can also override the initial Hive / Hive Engine node by passing a config object to the hiveRewards() factory in code. eg.

const analyzer = await hiveRewards({
  hiveNodeUrl: 'https://your.hive.node',
  hiveEngineRpcUrl: 'https://your.he.rpc',
  hiveEngineHistoryUrl: 'https://your.he.history',
});

Other Overrides:

Constructor Attribute Description Default
fetch Fetch API implementation npm cross-fetch
hiveJs pass in another @hiveio/hive-js version, if needed v2
log custom logger console
apiCallsDelay default wait time for api call retries 500 (with exp backoff)
priceCacheMins how long Hive price is cached for 10 mins
hiveHistoryLimit page size (max account‐history ops per call) 500
heHistoryLimit page size (max Hive-Engine history records per call) 250


Peakd's Beacon Wrapper

Wrapper for @peakd's Beacon APIs.

Usage:

import { peakdBeaconWrapper } from 'hiverewards';

const { getHealthyHiveNode, getHealthyHeNode, getHealthyHeHistoryNode } = peakdBeaconWrapper;
const hiveUrl = await getHealthyHiveNode();
const heUrl = await getHealthyHeNode();
const hehUrl = await getHealthyHeHistoryNode();

// Now you can configure your client:
hiveApi.api.setOptions({ url: hiveUrl });

...our use our Hive / Hive Engine client wrappers that automatically rotate healthy nodes:

import { healthyApisWrapper } from 'hiverewards';

const { hiveApiCall, hiveEngineApiCall, hiveEngineHistoryApiCall } = healthyApisWrapper;

const history = await hiveApiCall('getAccountHistory', ['cryptoshotsdoom', -1, 10]);
console.log(history);

const metrics = await hiveEngineApiCall({
  jsonrpc: '2.0',
  method:  'find',
  params: {
    contract: 'market',
    table:    'metrics',
    query:    { symbol: 'DOOM' },
    limit:    1,
    offset:   0
  },
  id: 1
});
console.log(metrics);

const history = await hiveEngineHistoryApiCall('cryptoshotstips', 20);
console.log(history);


Usage in CRYPTO SHOTS

DISCORD:

  • Earnings report for Daily Tournaments
  • Weekly/monthly Top Earners leaderboard
Image from post

GAME UI: Coming Soon


Coming Next

  • Support for additional Hive sidechains
  • Porting into Unity as an Open Source plugin


cs-logo.png

Support us

 

  • VOTE for our witness 🙇‍♂️

Image from post  


Comments (4)

aftabirshad's avatar @aftabirshad 4/28/2025

Nice work 👍

stickupboys's avatar @stickupboys 4/28/2025

untitled.gif

cryptoshots.nft's avatar @cryptoshots.nft 4/28/2025

untitled.gif

hivebuzz's avatar @hivebuzz 4/29/2025

Congratulations @crypto-shots! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

You received more than 300 upvotes.
Your next target is to reach 400 upvotes.

You can view your badges on your board and compare yourself to others in the Ranking If you no longer want to receive notifications, reply to this comment with the word STOP

Check out our last posts:

Hive Power Up Day - May 1st 2025
mickvir's avatar @mickvir 4/30/2025

Nice that would be very useful to project owners and users to track what they have earned from a game/project.

crypto-shots's avatar @crypto-shots 5/4/2025

Indeed. We could also offer it as a command in our Discord so that every user can check their earnings by running a command. (instead of relying on the post-tournament report and weekly/monthly earnings leaderboards)