Skip to content

Instantly share code, notes, and snippets.

@sdesalas
Forked from PraneshASP/createWallet.js
Created March 5, 2022 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sdesalas/522a208b071e887c5f6638d930364d74 to your computer and use it in GitHub Desktop.
Save sdesalas/522a208b071e887c5f6638d930364d74 to your computer and use it in GitHub Desktop.
Create a bitcoin wallet with this simple script.
//Import dependencies
const bip32 = require('bip32')
const bip39 = require('bip39')
const bitcoin = require('bitcoinjs-lib')
//Define the network
const network = bitcoin.networks.bitcoin //use networks.testnet for testnet
// Derivation path
const path = `m/49'/0'/0'/0` // Use m/49'/1'/0'/0 for testnet
let mnemonic = bip39.generateMnemonic()
const seed = bip39.mnemonicToSeedSync(mnemonic)
let root = bip32.fromSeed(seed, network)
let account = root.derivePath(path)
let node = account.derive(0).derive(0)
let btcAddress = bitcoin.payments.p2pkh({
pubkey: node.publicKey,
network: network,
}).address
console.log(`
Wallet generated:
- Address : ${btcAddress},
- Key : ${node.toWIF()},
- Mnemonic : ${mnemonic}
`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment