Skip to content

Instantly share code, notes, and snippets.

@kennethhutw
Created January 7, 2020 06:56
Show Gist options
  • Save kennethhutw/34cd99206499fd07633aae3bf964f1fd to your computer and use it in GitHub Desktop.
Save kennethhutw/34cd99206499fd07633aae3bf964f1fd to your computer and use it in GitHub Desktop.
const fs = require("fs")
let BITBOX = require('bitbox-sdk').BITBOX;
let bitbox = new BITBOX();
var mnemonic = bitbox.Mnemonic.generate()
const NETWORK = `mainnet`;
const filetime = new Date().getTime();
console.log("mnemonic",mnemonic);
// These objects used for writing wallet information out to a file.
let outStr ="mnemonic :" + mnemonic+ "\n"
const outObj = {}
// root seed buffer
const rootSeed = bitbox.Mnemonic.toSeed(mnemonic)
// master HDNode
const masterHDNode = bitbox.HDNode.fromSeed(rootSeed, NETWORK)
// Generate the first 10 seed addresses.
for (let i = 0; i < 10; i++) {
const childNode = masterHDNode.derivePath(`m/44'/145'/0'/0/${i}`)
console.log(`m/44'/145'/0'/0/${i}: ${bitbox.HDNode.toCashAddress(childNode)}`)
outStr += `m/44'/145'/0'/0/${i}: ${bitbox.HDNode.toCashAddress(childNode)}\n`
// Save the first seed address for use in the .json output file.
if (i === 0) {
outObj.cashAddress = bitbox.HDNode.toCashAddress(childNode)
outObj.legacyAddress = bitbox.HDNode.toLegacyAddress(childNode)
outObj.WIF = bitbox.HDNode.toWIF(childNode)
}
}
// Write the extended wallet information into a text file.
fs.writeFile("wallet-info-"+filetime+".txt", outStr, function(err) {
if (err) return console.error(err)
console.log(`wallet-info.txt written successfully.`)
})
// Write out the basic information into a json file for other example apps to use.
fs.writeFile("wallet-"+filetime+".json", JSON.stringify(outObj, null, 2), function(err) {
if (err) return console.error(err)
console.log(`wallet.json written successfully.`)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment