Created
January 7, 2020 06:56
-
-
Save kennethhutw/34cd99206499fd07633aae3bf964f1fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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