Skip to main content
GET
/
api
/
v1
/
ledger
/
tokens
/
{user_id}
Get Token Balance
curl --request GET \
  --url https://api.example.com/api/v1/ledger/tokens/{user_id}
{
  "balance": 6500
}

Overview

Retrieves the current token balance for a user in the BOOP Network ledger. The user ID is derived from the user-token share and is used for balance tracking across payments.
The user_id parameter is a hex-encoded SHA256 hash of the concatenated user-token share and “ledger” string.

Path Parameters

user_id
string
required
User identifier calculated by concatenating the user-token share with “ledger” string, then hashed using SHA256. Result is a 64-character hex string.

Response

balance
integer
required
Current token balance for the user (in smallest currency unit, e.g., cents)
{
  "balance": 6500
}

Usage Examples

async function getUserBalance(userTokenShare) {
  // Calculate user_id for ledger
  const crypto = require('crypto');
  const userId = crypto
    .createHash('sha256')
    .update(userTokenShare + 'ledger')
    .digest('hex');

  const response = await fetch(
    `https://dev.app.boop.it/api/v1/ledger/tokens/${userId}`,
    {
      headers: {
        'X-API-Key': 'your-api-key'
      }
    }
  );

  const { balance } = await response.json();
  return balance;
}

Balance Units

Token balances are stored and returned in the smallest currency unit:
  • USD: Cents (balance of 6500 = $65.00)
  • EUR: Cents (balance of 6500 = €65.00)
  • Cryptocurrency: Wei/satoshi depending on currency

Use Cases

Payment Processing

Check user balance before processing payments:
async function processPayment(userTokenShare, amount) {
  const balance = await getUserBalance(userTokenShare);

  if (balance < amount) {
    throw new Error('Insufficient balance');
  }

  // Proceed with payment...
}

Wallet Integration

Display current balance in user wallets or vendor interfaces.

Security Considerations

  • Never expose user-token shares in client-side code
  • Calculate user_id server-side only
  • Use HTTPS for all balance queries
  • Implement proper authentication and rate limiting

Rate Limits

  • 100 balance queries per minute per API key
  • 1000 balance queries per hour per API key