I've been working on something I think developers in the Hive ecosystem will find useful: an official SDK for HivePredict.
If you're not familiar, HivePredict is a prediction market platform built entirely on the Hive blockchain. Every market, every prediction, every resolution - it all happens on-chain via custom_json operations. The SDK lets you tap into all of that from your own apps.
The hivepredict SDK is a TypeScript/JavaScript package that gives you two things:
Zero dependencies. Works everywhere fetch is available - Node.js 18+, Deno, Bun, browsers. Ships as both ESM and CommonJS with full TypeScript types.
npm install hivepredict
The SDK wraps the HivePredict API with a clean, typed interface. Here's how it looks in practice:
import { HivePredict } from 'hivepredict';
const hp = new HivePredict();
// What's trending?
const { markets } = await hp.markets.trending();
for (const market of markets) {
console.log(`${market.title}`);
console.log(` Pool: ${market.totalPool} ${market.token}`);
console.log(` YES: ${market.yesPool} / NO: ${market.noPool}`);
console.log(` Closes: ${market.bettingClosesAt}`);
}
There are feeds for every angle - newest(), trending(), endingSoon(), resolved(), closed() - or use list() with filters:
// Crypto markets with the most volume
const crypto = await hp.markets.list({
category: 'crypto',
sort: 'most_volume',
limit: 10,
});
// Open sports markets
const sports = await hp.markets.open({ category: 'sports' });
Drill into a single market to get the full picture:
const market = await hp.markets.get('some-market-id');
console.log(market.title);
console.log(`Status: ${market.status}`);
console.log(`Resolution: ${market.resolutionType}`);
console.log(`Participants: ${market.participantCount}`);
console.log(`Outcomes:`, market.outcomePools);
// Who's betting on what?
const { predictions } = await hp.markets.predictions(market.id);
for (const p of predictions) {
console.log(` ${p.hiveUsername} bet ${p.amount} ${market.token} on ${p.outcome}`);
}
// How did the odds move over time?
const { snapshots } = await hp.markets.snapshots(market.id, { range: '1w' });
// Community discussion
const { comments } = await hp.markets.comments(market.id);
// Resolution evidence
const { proofs } = await hp.markets.proofs(market.id);
const { user, stats } = await hp.users.get('someuser');
console.log(`${user.hiveUsername}`);
console.log(` Predictions: ${stats.totalPredictions}`);
console.log(` Win rate: ${stats.winRate}`);
console.log(` Total earned: ${stats.totalEarnings}`);
// Their prediction history
const { predictions } = await hp.users.predictions('someuser');
// Markets they created
const { markets } = await hp.users.markets('someuser');
A real-time transparency feed of everything happening on the platform:
const { events } = await hp.activity.list({
types: ['bet_placed', 'market_resolved'],
limit: 20,
});
for (const event of events) {
console.log(`${event.account} - ${event.eventType} - ${event.marketTitle}`);
}
const stats = await hp.stats();
console.log(`${stats.totalMarkets} markets`);
console.log(`${stats.totalUsers} users`);
console.log(`${stats.totalVolume} total volume`);
This is where it gets interesting. Since HivePredict runs on Hive, all state changes are custom_json operations. The SDK builds these operations for you with full type safety - you just broadcast them with HiveKeychain or @hiveio/dhive.
Predictions are a paired transfer + custom_json in one transaction:
import { operations } from 'hivepredict';
const marketId = 'some-market-id';
// Build the transfer (the actual stake)
const transfer = operations.predictionTransfer(
'hivepredict', // platform account
marketId,
'YES',
'10.000 HIVE',
);
// Build the custom_json (the metadata)
const customJson = operations.placePrediction('myusername', {
market_id: marketId,
outcome: 'YES',
amount: '10.000',
tx_id: '',
});
// Broadcast via HiveKeychain
window.hive_keychain.requestBroadcast(
'myusername',
[
['transfer', {
from: 'myusername',
to: transfer.to,
amount: transfer.amount,
memo: transfer.memo,
}],
['custom_json', customJson],
],
'Active',
(response) => console.log(response),
);
import { operations } from 'hivepredict';
const op = operations.createMarket('myusername', {
market_id: crypto.randomUUID(),
title: 'Will ETH flip BTC market cap in 2026?',
description: 'Based on CoinGecko market cap data at resolution time.',
category: 'crypto',
token: 'HIVE',
outcomes: ['YES', 'NO'],
creator_side: 'NO',
stake_cap: 5000,
min_participants: 3,
resolution_type: 'manual',
resolution_source: null,
resolution_criteria: 'Resolves YES if ETH market cap exceeds BTC on CoinGecko at resolution time.',
betting_closes_at: '2026-12-30T00:00:00Z',
resolves_at: '2026-12-31T00:00:00Z',
});
// Broadcast via HiveKeychain
window.hive_keychain.requestCustomJson(
'myusername', op.id, 'Posting', op.json, 'Create Market',
(response) => console.log(response),
);
import { operations } from 'hivepredict';
// Comment on a market
const comment = operations.comment('myusername', {
market_id: 'some-market-id',
body: 'The on-chain data clearly supports YES here.',
});
// Submit resolution proof
const proof = operations.submitProof('myusername', {
market_id: 'some-market-id',
outcome: 'YES',
note: 'CoinGecko shows the price crossed the threshold on March 15.',
source_urls: ['https://coingecko.com/en/coins/bitcoin'],
});
// Vote on someone else's proof
const vote = operations.voteProof('myusername', {
market_id: 'some-market-id',
proof_id: 'proof-uuid',
vote: 'up',
});
// All of these are just custom_json - broadcast with dhive:
await client.broadcast.json(comment, postingKey);
Some ideas:
The SDK throws typed errors so you can handle failures cleanly:
import { HivePredict, HivePredictError, NetworkError } from 'hivepredict';
try {
const market = await hp.markets.get('bad-id');
} catch (err) {
if (err instanceof HivePredictError) {
// API error - market not found, rate limited, etc.
console.error(`${err.statusCode}: ${err.message}`);
} else if (err instanceof NetworkError) {
// Connection failed
console.error('Network issue:', err.message);
}
}
npm install hivepredict
The SDK is MIT licensed. If you run into issues or have feature requests, open an issue on GitHub. If you build something with it, I'd love to see it.