Node 生成比特币地址和私钥
千万注意,以下代码不可信不可信,在正式环境使用要谨慎。
const bitcoin = require("bitcoinjs-lib"); const dhttpCallback = require('dhttp/200'); const env = process.env[2] ? process.env[2] : 'production'; const dev = env == 'production' ? true : false; const dhttp = options => new Promise((resolve, reject) => { return dhttpCallback(options, (err, data) => { if (err) return reject(err) else return resolve(data) }) }) async function gen() { do { var ok = false; var keyPair = bitcoin.ECPair.makeRandom(); var { address } = bitcoin.payments.p2pkh({ pubkey: keyPair.publicKey }) if ( !dev ) { var result = await dhttp({ method: 'GET', url: 'https://blockchain.info/rawaddr/' + address }) if( result.n_tx == 0 && result.total_received == 0 && result.total_sent == 0) { ok = true; } } else { ok = true } var pkey = keyPair.toWIF(); console.log(address + " " + pkey); } while(!ok) } gen();
使用前首先需要安装对应的模块
npm install bitcoinjs-lib dhttp
目前尚无回复