Blockchain utility methods
ChainGate provides a set of blockchain utility methods designed to help developers interact with all blockchains.
These utilities abstract low-level API calls and offer a consistent developer experience across chains. You can use them to:
- Query balances and UTXOs
- Broadcast transactions
- Retrieve transaction and block data
- Estimate gas and fees
- Interact with smart contracts
- Handle signing and address conversions
These utilities are ideal for wallets, explorers, and blockchain tools that operate across multiple chains.
Initialization
To start using the utility methods, first initialize the utils interface:
import { initializeUtils } from 'chaingate'
const utils = await initializeUtils({ apiKey: 'your-api-key' })
const bitcoinUtils = utils.currency('bitcoin')
This provides access to all currency-specific utilities through a single entry point.
Usage per currency
After calling initializeUtils()
, you can access the utilities for any supported currency using:
const polygonUtils = utils.currency('polygon')
Each currency provides its own relevant methods. For example:
bitcoin
:addressUtxos()
,transactionDetails()
,latestBlock()
polygon
:estimateGas()
,callSmartContractRaw()
,networkStatus()
Common methods
All currency utilities provide a shared set of methods, regardless of whether the chain is UTXO or EVM-based:
addressBalance(address)
— Get confirmed and unconfirmed balancespublicKeyToAddress(publicKey)
— Convert a public key to an address stringsignMessage(message, privateKey)
— Sign a messageverifySignedMessage(message, signature, address)
— Verify a signed messageamount(value, unit)
— Create an amount from a base or minimal unitamountFiat(value, fiatCurrency)
— Convert a fiat amount into a crypto amountfiatRate(fiatCurrency)
— Get the current rate for the crypto/fiat pairlatestBlock()
— Get the latest block for the networkblockByHeight(height)
— Fetch block data by block heightblockByHash(hash)
— Fetch block data by block hashtransactionDetails(txId)
— Retrieve full details of a transactionbroadcastTransaction(rawTx)
— Broadcast raw transaction data
UTXO utilities
UtxoCurrencyUtils
adds additional methods for managing unspent outputs and accessing blockchain history.
Available methods
addressUtxos(address)
— List UTXOs associated with an addressaddressHistory(address)
— Get historical transactionsgetFeeRate()
— Get recommended fees based on network congestionmempoolTransactions()
— Get current mempool contents
EVM utilities
EvmCurrencyUtils
includes additional methods tailored to EVM-compatible networks.
Available methods
addressTransactionCount(address)
— Get transaction noncecallSmartContractRaw(contract, data)
— Low-level smart contract callestimateGas(from, to, amount, nonce, data)
— Estimate gas for a transactiongetFeeRate()
— Retrieve current gas pricesnetworkStatus()
— Returns real-time metrics about the network, including average block time, EIP-1559 fee details (base fee and predicted tips), network congestion, and estimated transaction costs.
Working with amounts
Whenever a utility method returns or requires an amount, it uses a specialized object that handles decimal precision, arithmetic operations, conversions, and formatted display.
This object provides methods like:
.str
— Human-readable string with symbol (e.g.,0.00231 BTC
).baseAmount
— Decimal value in base unit.minimalUnitAmount
— Value in minimal unit (e.g., satoshis, wei).plus(amount)
/.minus(amount)
— Perform arithmetic.toFiat(fiatCurrency)
— Convert to fiat equivalent
This ensures safe calculations and consistent formatting across all blockchains.
Key points
- Unified abstraction: The same API design across chains
- Chain-aware methods: Adapts logic based on currency type
- Smart contract support: For all EVM-based networks
- Safe math:
CurrencyAmount
handles decimals correctly