Place Predictions from an App

Place Predictions from an App

The REST API is read-only. A partner app places a prediction by asking the user to sign one Hive transaction containing a token transfer and a custom_json operation. Keep both operations in the same transaction so an invalid prediction can be matched to its transfer.

1. Find Skateboarding Markets

curl -s "https://hivepredict.app/api/markets/open?category=skate&limit=20"   | jq '.markets[] | {id, title, status, token, outcomes, outcomeLabels, stakeCap, tradingCutoff}'

Use the returned id as market_id. Display outcomeLabels to users, but submit the matching key from outcomes.

2. Check the User and Market

curl -s "https://hivepredict.app/api/users/your-account/eligibility?action=predict"
curl -s "https://hivepredict.app/api/markets/MARKET_ID"

Only continue when the account is eligible, the market status is pending or active, the current time is before tradingCutoff, and the selected outcome appears in outcomes. The transfer token must match the market token. Amounts use exactly three decimal places and the minimum prediction is 1.000.

3. Read the Current Transaction Contract

curl -s https://hivepredict.app/api/public   | jq '.onChainWrites.placePrediction'

This manifest supplies the configured platform account, operation id, Hive Engine transfer format and confirmation endpoint. Read it at runtime instead of copying the platform account into your app.

4. Broadcast with Hive Keychain

This example covers native HIVE and HBD markets. Hive Engine markets use the transfer template in the public manifest, followed by the same prediction operation.

const account = 'your-hive-account';
const marketId = 'MARKET_ID';
const outcome = 'YES';
const amount = '1.000';

const [manifest, market] = await Promise.all([
  fetch('https://hivepredict.app/api/public').then((res) => res.json()),
  fetch('https://hivepredict.app/api/markets/' + marketId).then((res) => res.json()),
]);

const contract = manifest.onChainWrites.placePrediction;
const asset = amount + ' ' + market.token;
const memo = market.id + ':' + outcome;
const operations = [
  ['transfer', {
    from: account,
    to: contract.platformAccount,
    amount: asset,
    memo,
  }],
  ['custom_json', {
    required_auths: [account],
    required_posting_auths: [],
    id: contract.operationId,
    json: JSON.stringify({
      market_id: market.id,
      outcome,
      amount: asset,
      tx_id: '',
    }),
  }],
];

window.hive_keychain.requestBroadcast(
  account,
  operations,
  'Active',
  (result) => console.log(result),
);

HiveSigner clients can broadcast the same operations array after the user grants active authority. Never ask for or store a user’s active key.

5. Confirm Indexing

A successful wallet response means Hive accepted the transaction. The API may take a few seconds to index it. Poll /api/markets/MARKET_ID/predictions and match the returned account, outcome and transaction id before showing the prediction as confirmed.