API Reference Overview
Complete API reference for the Hoosat Browser SDK.
Core Modules
Browser-native cryptographic operations.
Key Methods:
generateKeyPair(network?)- Generate ECDSA key pairimportKeyPair(privateKey, network?)- Import walletsignTransactionInput(tx, index, privateKey, utxo)- Sign transactiongetTransactionId(tx)- Calculate TX IDblake3Hash(data)- BLAKE3 hashing
REST API client for Hoosat nodes.
Key Methods:
getBalance(address)- Get address balancegetUtxos(addresses)- Get UTXOssubmitTransaction(tx)- Submit signed transactiongetFeeEstimate()- Get fee recommendationsgetNetworkInfo()- Get network information
Transaction builder with fluent API.
Key Methods:
addInput(utxo, privateKey?)- Add inputaddOutput(address, amount)- Add outputaddChangeOutput(address)- Add changesetFee(fee)- Set feesign(privateKey?)- Sign transaction
Message signing for authentication.
Key Methods:
signMessage(privateKey, message)- Sign messageverifyMessage(signature, message, publicKey)- Verify signaturecreateSignedMessage(privateKey, message, address)- Create signed message objectverifySignedMessage(signedMessage, publicKey)- Verify signed message
QR code generation for payments.
Key Methods:
generateAddressQR(address, options?)- Generate address QRgeneratePaymentQR(params, options?)- Generate payment QRbuildPaymentURI(params)- Build payment URIparsePaymentURI(uri)- Parse payment URI
Utility functions.
Key Methods:
amountToSompi(htn)- Convert HTN to sompisompiToAmount(sompi)- Convert sompi to HTNisValidAddress(address)- Validate addressgetAddressNetwork(address)- Get address networktruncateAddress(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
- Examples - Working examples