Import from mnemonic phrase
A mnemonic phrase (12, 15, 18, 21 or 24 words) serves as a human-readable backup for your wallet.
ChainGate adheres to the BIP39 standard, enabling you to import mnemonics from nearly any wallet provider, such as MetaMask, Ledger, or Trezor. Additionally, you can use the phrase generated by the newWallet() function.
Phrases are supported in: Czech, English, French, Italian, Japanese, Korean, Portuguese, Simplified Chinese, Spanish, and Traditional Chinese.
Treat your mnemonic phrase like a password. If someone obtains it, they can access all assets associated with your wallet.
Import from a valid phrase
The operation is synchronous and does not require an API key:
import { importWallet } from 'chaingate'
const wallet = importWallet({ phrase: 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about' })
Using the wallet
Connect the wallet to a network to derive addresses, check balances, and more:
import { importWallet, ChainGate } from 'chaingate'
const wallet = importWallet({ phrase: 'valid phrase here ...' })
const cg = new ChainGate({ apiKey: 'your-api-key' })
const bitcoin = cg.connect(cg.networks.bitcoin, wallet)
console.log(await bitcoin.address())
Check phrase validity
Before importing, validate the mnemonic phrase using isValidPhrase():
import { isValidPhrase, importWallet } from 'chaingate'
const phrase = 'abandon abandon about ...'
if (!isValidPhrase(phrase)) {
throw new Error('Invalid recovery phrase')
}
const wallet = importWallet({ phrase })
isValidPhrase() returns true only if the phrase follows BIP39 standards and has a valid word count (12/15/18/21/24 words).
Access the phrase
If you need to retrieve the phrase from an already initialized wallet:
const phraseEntity = await wallet.getPhrase()
console.log(phraseEntity.toString())
Never log your phrase in a production environment!
Exporting a wallet
To back up or persist your wallet, you need to serialize it.