Skip to content

Instantly share code, notes, and snippets.

@pipethedev
Created March 29, 2021 16:45
Show Gist options
  • Select an option

  • Save pipethedev/deb86dd2b6d378af1f43043a742a455c to your computer and use it in GitHub Desktop.

Select an option

Save pipethedev/deb86dd2b6d378af1f43043a742a455c to your computer and use it in GitHub Desktop.
console.log('\n');
let bitcore = require('bitcore-lib');
let privateKeyWIF = 'cVumzeajS3k7QeUb8dcUiF5JH43uTLZUmZSYM87rRLbJvv4zJnX8';
let privateKey = bitcore.PrivateKey.fromWIF(privateKeyWIF);
let address = privateKey.toAddress();
console.log('test-net address:' + address);
let value = new Buffer('this to generate random shit');
let hash = bitcore.crypto.Hash.sha256(value);
let bn = bitcore.crypto.BN.fromBuffer(hash);
let address2 = new bitcore.PrivateKey(bn, 'testnet').toAddress();
console.log('test-net address2' + ':' + address2);
let Insight = require('bitcore-explorers').Insight;
let insight = new Insight('testnet');
insight.getUnspentUtxos(address, (err, utxos) => {
if(err){
//Handle errors
}else{
console.log(utxos);
let tx = bitcore.Transaction();
tx.from(utxos);
tx.to(address2, 10000); //0.001 BTC
tx.serialize();
tx.addData();
insight.broadcast(tx, (err, returnTxId) => {
if (err){
//handleErrors
}else{
console.log('successful broadcast:' + returnTxId)
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment