Addresses
In cryptocurrency, an address is a publicly shareable identifier you use to receive funds. Each blockchain has its own address format (e.g., Bitcoin addresses look different from Ethereum addresses).
To get an address, connect your wallet to a network using cg.connect() and call .address().
Example: Ethereum address
import { newWallet, ChainGate } from 'chaingate'
const { wallet } = newWallet()
const cg = new ChainGate({ apiKey: 'your-api-key' })
const ethereum = cg.connect(cg.networks.ethereum, wallet)
const address = await ethereum.address()
console.log(address)
// e.g., "0xE7c19D5A90352b5eE0144363D1191E2549Ca2146"
Multiple addresses (HD wallets)
For HD wallets (phrase, seed, or xpriv), you can derive multiple addresses by passing an index:
const address0 = await ethereum.address() // index 0 (default)
const address1 = await ethereum.address({ index: 1 }) // index 1
const address2 = await ethereum.address({ index: 2 }) // index 2
UTXO address types
For UTXO networks (Bitcoin, Litecoin, etc.), you can also specify the address type:
const bitcoin = cg.connect(cg.networks.bitcoin, wallet)
// Default (segwit for Bitcoin)
const segwit = await bitcoin.address()
// Taproot
const taproot = await bitcoin.address({ addressType: 'taproot' })
// Legacy
const legacy = await bitcoin.address({ addressType: 'legacy' })
Each address type uses its own derivation path automatically. You can also override the derivation path:
const custom = await bitcoin.address({
addressType: 'legacy',
derivationPath: "m/44'/0'/0'/0"
})
How addresses work
- Shareable: Addresses are safe to share publicly. They only reveal where funds can be sent, not how they can be accessed.
- Unique formats: Each blockchain has its own address style (Bitcoin
bc1..., Ethereum0x..., etc.). - Derivation paths: HD wallets can generate many addresses from a single seed. The
indexoption increments the last segment of the derivation path.
Using different networks
Connect the same wallet to any supported network:
const btcAddr = await cg.connect(cg.networks.bitcoin, wallet).address()
const ethAddr = await cg.connect(cg.networks.ethereum, wallet).address()
const ltcAddr = await cg.connect(cg.networks.litecoin, wallet).address()
Key points
- Addresses are public: Safe to share so others can send you funds.
- One wallet, multiple networks: A single wallet can derive addresses for any supported network.
- HD wallets: Use
{ index }to derive multiple addresses. - UTXO address types: Use
{ addressType }to choose between segwit, taproot, or legacy. - Single-key wallets:
PrivateKeyWalletandPublicKeyWalletonly supportindex: 0. - View-only wallets:
XpubWalletandPublicKeyWalletcan derive addresses but cannot sign transactions.