Skip to content

Instantly share code, notes, and snippets.

@PraneshASP
Last active March 12, 2024 11:51
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save PraneshASP/df3f3f0af02fea728ad49bfa0cae7aff to your computer and use it in GitHub Desktop.
Save PraneshASP/df3f3f0af02fea728ad49bfa0cae7aff 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}
`)
@uinguzero
Copy link

Hi,
I wanted to use your script to create a number of wallets.
But I get a type error: bip32.fromSeed not a valid function.

I did no install bip32

Can you please help me out?

@varunvasista
Copy link

Use bip32 2.0.6 version

@Pocolee35
Copy link

Use bip32 2.0.6 version

@vjhameed
Copy link

Hey there

i get an error on bitcoin.payments.p2pkh

it says not enough data

@devNica
Copy link

devNica commented Jun 9, 2022

Thank you very much for the contribution

@Klos54
Copy link

Klos54 commented Aug 3, 2022

Hey there,

I got a btc address, seed phase and private key but how to access funds on the wallet with that ? What is the wallet name I need to get access the wallet please ?

@Leodaz
Copy link

Leodaz commented Sep 20, 2023

No funciona y le falta muchas cosas para que sea útil ,agradezco el esfuerzo pero no tiene utilidad en Windows podrías colocar un ejm mucho mas útil?

@fofotara
Copy link

TypeError: Cannot read property 'networks' of undefined,

@pagarevijayy
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment