ChainGate 1.3 — Real-time events in the SDK: onBlock, onBalance, onTransaction
Earlier this week the API learned to push events over WebSocket. Today the SDK does the work for you: subscribe with a callback and stop polling. New blocks, balance changes, transactions, pending activity and contract interactions arrive as typed events on Bitcoin, Litecoin, Dogecoin, Bitcoin Cash, Bitcoin Testnet, Ethereum and Avalanche — no sockets to open, no reconnection code, no JSON to parse.
import { ChainGate } from 'chaingate'
const cg = new ChainGate()
const btc = cg.explore(cg.networks.bitcoin)
btc.onBlock((block) => console.log(`Block ${block.height} — ${block.numTxs} transactions`))
btc.onBalance('bc1q...', async ({ confirmed }) => {
console.log('New balance:', confirmed.base(), 'BTC', '≈', await confirmed.toCurrency('usd'), 'USD')
})