Skip to main content

Overview

The KDP API uses specific data types and formats to ensure consistency and precision when handling blockchain data. This guide explains the key data types you’ll encounter.

Basic Types

Amounts (SOMPI)

All monetary amounts in the Kaspa blockchain are represented in SOMPI, the smallest unit of Kaspa.
  • 1 KAS = 100,000,000 SOMPI
  • Amounts are returned as strings to preserve precision
  • Always use appropriate libraries for big number arithmetic
{
  "amount": "31112708372"  // 311.12708372 KAS
}

Hashes

All hashes (transaction IDs, block hashes) are 64-character hexadecimal strings:
{
  "transactionId": "a7177c55769381a56c126e458c8bb6046613b8a8d45c2f8d3ca5dc71a065279a",
  "blockHash": "2a0c51fab2a7c7a187299e087a244d1e70acdc75e0214a661c62761e2d6bbf4f"
}

Addresses

Kaspa addresses use the Bech32 format with the kaspa: prefix:
{
  "address": "kaspa:qpzpfwcsqsxhxwup26r55fd0ghqlhyugz8cp6y3wxuddc02vcxtjg75pspnwz"
}

Timestamps

Timestamps are Unix timestamps in milliseconds:
{
  "blockTime": 1749531022210  // February 9, 2025 12:30:22.210 GMT
}

Complex Types

Script Public Keys

Script public keys are represented in hexadecimal format:
{
  "scriptPublicKey": "2010fdab002cff0ac15bfc8b982c5a616bef9e5a66f0c655f4f63f7d1cef39d2b4ac",
  "scriptPublicKeyType": "pubkey",
  "scriptPublicKeyAddress": "kaspa:qqg0m2cq9nls4s2mlj9estz6v947l8j6vmcvv4057clh688088ftg7ce6p895"
}

Blue Score / DAA Score

Blue score and DAA score represent the position of a block in the blockchain:
{
  "blueScore": "107206794",
  "daaScore": "107206794"
}

Type Conversion Examples

JavaScript/TypeScript

// Converting SOMPI to KAS
function sompiToKas(sompi: string): number {
  return Number(sompi) / 100_000_000;
}

// Converting KAS to SOMPI
function kasToSompi(kas: number): string {
  return Math.floor(kas * 100_000_000).toString();
}

// Working with big numbers
import { BigNumber } from 'bignumber.js';

function addAmounts(amount1: string, amount2: string): string {
  const sum = new BigNumber(amount1).plus(amount2);
  return sum.toString();
}

// Converting timestamp to Date
function timestampToDate(timestamp: number): Date {
  return new Date(timestamp);
}

Python

from decimal import Decimal
from datetime import datetime

# Converting SOMPI to KAS
def sompi_to_kas(sompi: str) -> Decimal:
    return Decimal(sompi) / Decimal('100000000')

# Converting KAS to SOMPI
def kas_to_sompi(kas: Decimal) -> str:
    return str(int(kas * Decimal('100000000')))

# Working with amounts
def add_amounts(amount1: str, amount2: str) -> str:
    return str(Decimal(amount1) + Decimal(amount2))

# Converting timestamp to datetime
def timestamp_to_datetime(timestamp: int) -> datetime:
    return datetime.fromtimestamp(timestamp / 1000)

Special Values

Null Values

Some fields may be null when data is not available:
{
  "acceptingBlockHash": null,  // Transaction not yet accepted
  "amountSent": null,          // Unable to determine amount sent
  "fee": null                  // Unable to calculate fee
}

Empty Arrays

Arrays are never null, but may be empty:
{
  "inputs": [],      // Coinbase transaction has no inputs
  "blockHashes": []  // Transaction not in any blocks yet
}

Best Practices

  1. Use string arithmetic: Always use appropriate libraries for handling large numbers
  2. Validate addresses: Check address format before making requests
  3. Handle null values: Always check for null before using optional fields
  4. Preserve precision: Don’t convert amounts to floating point numbers
  5. Use constants: Define constants for conversions (e.g., SOMPI_PER_KAS)
I