Network properties
Each network in cg.networks is a NetworkDescriptor instance. Depending on the network type (UTXO or EVM), different properties and methods are available, including an address validator that works across every supported chain.
Common to all networks
Every NetworkDescriptor exposes:
id(string) — Stable identifier (e.g.,'bitcoin','ethereum').name(string) — Human-readable name (e.g., Bitcoin, Ethereum).symbol(string) — Ticker symbol for the native asset (e.g.,BTC,ETH).type('evm'|'utxo') — Network type.decimals(number) — Decimal places for the native asset (e.g., 8 for BTC, 18 for ETH).isTestnet(boolean) — Whether this is a testnet network.hasOwnToken(boolean) — Whether the network has its own native token.nativeToken(object) — Native token metadata withsymbolandnamefields.defaultAddressType(string) — Default address encoding (e.g.,'segwit','eoa').addressTypes(object) — Supported address types with their derivation paths.rpcUrl(string) — Pre-built JSON-RPC endpoint URL with the API key appended.chainId(number, EVM only) — EVM chain ID per EIP-155.
import { ChainGate } from 'chaingate'
const cg = new ChainGate()
const btc = cg.networks.bitcoin
console.log(btc.id) // 'bitcoin'
console.log(btc.name) // 'Bitcoin'
console.log(btc.symbol) // 'BTC'
console.log(btc.type) // 'utxo'
console.log(btc.decimals) // 8
console.log(btc.isTestnet) // false
console.log(btc.defaultAddressType) // 'segwit'
UTXO networks
UtxoNetworkDescriptor extends the base with address types such as segwit, taproot, and legacy, each with their own derivation path. Additional methods:
publicKeyToAddress(publicKey, addressType?)— Derive an address from a public key.isValidAddress(address)— Check if a string is a valid address for this network.identifyAddressType(address)— Detect the detailed address type from an address string (e.g.'segwit-p2wpkh','legacy-p2pkh','taproot-p2tr').
const btc = cg.networks.bitcoin
// Derive a segwit address from a public key
const address = btc.publicKeyToAddress(publicKeyBytes, 'segwit')
// Validate an address
btc.isValidAddress('bc1q...') // true
btc.isValidAddress('invalid') // false
// Identify address type
const type = btc.identifyAddressType('bc1q...')
console.log(type) // 'segwit-p2wpkh'
tip
See Validate addresses for a complete list of detailed address types and more examples.
EVM networks
EvmNetworkDescriptor exposes:
publicKeyToAddress(publicKey)— Derive an EIP-55 checksummed address.isValidAddress(address)— Check if a string is a valid EVM address, with EIP-55 checksum verification for mixed-case addresses.chainId(number) — EVM chain ID per EIP-155.
const eth = cg.networks.ethereum
const address = eth.publicKeyToAddress(publicKeyBytes)
console.log(address) // '0xAb5801a7...'
console.log(eth.chainId) // 1
// Validate an address (EIP-55 checksum is verified automatically)
eth.isValidAddress('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045') // true
eth.isValidAddress('not-an-address') // false
Detect if a network is EVM-compatible
import { ChainGate, EvmNetworkDescriptor } from 'chaingate'
const cg = new ChainGate()
const network = cg.networks.ethereum
if (network instanceof EvmNetworkDescriptor) {
console.log('Chain ID:', network.chainId) // 1
}