Import from extended private key
An xpriv (extended private key) is a Base58-encoded string that represents a node in a hierarchical deterministic (HD) key tree. It allows deriving child keys and addresses, just like a phrase or seed wallet, but starts from a specific point in the key hierarchy.
Keep your xpriv safe!
An xpriv grants full access to derive private keys and sign transactions for all child paths. If someone obtains it, they can control all associated funds.
Import from a valid xpriv
The operation is synchronous:
import { importWallet } from 'chaingate'
const wallet = importWallet({ xpriv: 'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi' })
Using the wallet
import { importWallet, ChainGate } from 'chaingate'
const wallet = importWallet({ xpriv: 'xprv9s21ZrQH143K...' })
const cg = new ChainGate({ apiKey: 'your-api-key' })
const bitcoin = cg.connect(cg.networks.bitcoin, wallet)
const address0 = await bitcoin.address()
const address1 = await bitcoin.address({ index: 1 })
Key points
- HD wallet: Supports derivation of multiple addresses via the
indexoption. - Synchronous: No API key or async call needed for import.
- No phrase access: Unlike phrase wallets, you cannot retrieve a mnemonic phrase from an xpriv wallet.
- Signing supported: The xpriv contains private key material, so transactions can be signed.
Exporting a wallet
To back up or persist your wallet, you need to serialize it.