Skip to main content

API Reference Overview

Complete API reference for the Hoosat Browser SDK.

Core Modules

Browser-native cryptographic operations.

Key Methods:

  • generateKeyPair(network?) - Generate ECDSA key pair
  • importKeyPair(privateKey, network?) - Import wallet
  • signTransactionInput(tx, index, privateKey, utxo) - Sign transaction
  • getTransactionId(tx) - Calculate TX ID
  • blake3Hash(data) - BLAKE3 hashing

REST API client for Hoosat nodes.

Key Methods:

  • getBalance(address) - Get address balance
  • getUtxos(addresses) - Get UTXOs
  • submitTransaction(tx) - Submit signed transaction
  • getFeeEstimate() - Get fee recommendations
  • getNetworkInfo() - Get network information

Transaction builder with fluent API.

Key Methods:

  • addInput(utxo, privateKey?) - Add input
  • addOutput(address, amount) - Add output
  • addChangeOutput(address) - Add change
  • setFee(fee) - Set fee
  • sign(privateKey?) - Sign transaction

Message signing for authentication.

Key Methods:

  • signMessage(privateKey, message) - Sign message
  • verifyMessage(signature, message, publicKey) - Verify signature
  • createSignedMessage(privateKey, message, address) - Create signed message object
  • verifySignedMessage(signedMessage, publicKey) - Verify signed message

QR code generation for payments.

Key Methods:

  • generateAddressQR(address, options?) - Generate address QR
  • generatePaymentQR(params, options?) - Generate payment QR
  • buildPaymentURI(params) - Build payment URI
  • parsePaymentURI(uri) - Parse payment URI

Utility functions.

Key Methods:

  • amountToSompi(htn) - Convert HTN to sompi
  • sompiToAmount(sompi) - Convert sompi to HTN
  • isValidAddress(address) - Validate address
  • getAddressNetwork(address) - Get address network
  • truncateAddress(address) - Truncate for display

Quick Reference

Generate Wallet

import { HoosatCrypto } from 'hoosat-sdk-web';

const wallet = HoosatCrypto.generateKeyPair('mainnet');

Check Balance

import { HoosatWebClient } from 'hoosat-sdk-web';

const client = new HoosatWebClient({
baseUrl: 'https://proxy.hoosat.net/api/v1'
});

const balance = await client.getBalance(address);

Send Transaction

import { HoosatTxBuilder, HoosatUtils } from 'hoosat-sdk-web';

const builder = new HoosatTxBuilder();

utxos.forEach(utxo => builder.addInput(utxo, wallet.privateKey));

builder
.addOutput(recipient, HoosatUtils.amountToSompi('1.0'))
.setFee('2500')
.addChangeOutput(wallet.address);

const signed = builder.sign();
const result = await client.submitTransaction(signed);

Sign Message

import { HoosatSigner } from 'hoosat-sdk-web';

const signature = HoosatSigner.signMessage(
wallet.privateKey.toString('hex'),
message
);

const isValid = HoosatSigner.verifyMessage(
signature,
message,
wallet.publicKey.toString('hex')
);

Generate QR

import { HoosatQR } from 'hoosat-sdk-web';

const qr = await HoosatQR.generatePaymentQR({
address: merchantAddress,
amount: 100,
label: 'Coffee Shop'
});

Type Definitions

KeyPair

interface KeyPair {
address: string;
publicKey: Buffer;
privateKey: Buffer;
}

Transaction

interface Transaction {
version: number;
inputs: TransactionInput[];
outputs: TransactionOutput[];
lockTime: string;
subnetworkId: string;
gas: string;
payload: string;
}

UTXO

interface UtxoForSigning {
outpoint: {
transactionId: string;
index: number;
};
utxoEntry: {
amount: string;
scriptPublicKey: {
scriptPublicKey: string;
version: number;
};
blockDaaScore: string;
isCoinbase: boolean;
};
}

Constants

// Unit conversion
const SOMPI_PER_HTN = 100000000n;

// Network prefixes
const MAINNET_PREFIX = 'hoosat:';
const TESTNET_PREFIX = 'hoosattest:';

// Spam protection
const MAX_RECIPIENT_OUTPUTS = 2;
const MAX_TOTAL_OUTPUTS = 3;

// Dust threshold
const DUST_THRESHOLD = 1000n;

Next Steps