Archive post
Introducing the HivePredict SDK - Build on Prediction Markets
• beggars
I've been working on something I think developers in the Hive ecosystem will find useful: an official SDK for HivePredict
I've been working on something I think developers in the Hive ecosystem will find useful: an official SDK for [HivePredict](https://hivepredict.app).
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.
## What is it?
The [hivepredict SDK](https://github.com/Vheissu/hivepredict-sdk) is a TypeScript/JavaScript package that gives you two things:
1. **Read access** to all public HivePredict data - markets, predictions, payouts, user profiles, activity feeds, and more
2. **Operation builders** for writing to the Hive blockchain - create markets, place predictions, post comments, submit proofs, all with proper types
Zero dependencies. Works everywhere `fetch` is available - Node.js 18+, Deno, Bun, browsers. Ships as both ESM and CommonJS with full TypeScript types.
```bash
npm install hivepredict
```
## Reading Data
The SDK wraps the HivePredict API with a clean, typed interface. Here's how it looks in practice:
### Browse Markets
```typescript
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:
```typescript
// 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' });
```
### Market Detail
Drill into a single market to get the full picture:
```typescript
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);
```
### Users
```typescript
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');
```
### Activity Feed
A real-time transparency feed of everything happening on the platform:
```typescript
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}`);
}
```
### Platform Stats
```typescript
const stats = await hp.stats();
console.log(`${stats.totalMarkets} markets`);
console.log(`${stats.totalUsers} users`);
console.log(`${stats.totalVolume} total volume`);
```
## Writing to the Blockchain
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`.
### Place a Prediction
Predictions are a paired transfer + custom_json in one transaction:
```typescript
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),
);
```
### Create a Market
```typescript
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),
);
```
### Comment, Prove, Vote
```typescript
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);
```
## What Could You Build?
Some ideas:
- **Dashboards** - portfolio trackers, leaderboards, market analytics
- **Bots** - arbitrage between markets, automated market making, alert systems
- **Notifications** - watch specific markets or users, get alerts on resolution
- **Integrations** - embed prediction markets in your Hive frontend, Discord bot for market updates
- **Mobile apps** - the full HivePredict experience in a native app
- **Data analysis** - historical market performance, user behaviour, prediction accuracy
## Error Handling
The SDK throws typed errors so you can handle failures cleanly:
```typescript
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);
}
}
```
## Get Started
```bash
npm install hivepredict
```
- **GitHub**: [github.com/Vheissu/hivepredict-sdk](https://github.com/Vheissu/hivepredict-sdk)
- **Platform**: [hivepredict.app](https://hivepredict.app)
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.