Skip to content

Instantly share code, notes, and snippets.

@Anderson-Juhasc
Last active October 19, 2016 23:46
Show Gist options
  • Save Anderson-Juhasc/b0948c7aad5fe0ff84ea7e27783ce0f6 to your computer and use it in GitHub Desktop.
Save Anderson-Juhasc/b0948c7aad5fe0ff84ea7e27783ce0f6 to your computer and use it in GitHub Desktop.
var bitcore = require('bitcore-lib');
bitcore.Networks.defaultNetwork = bitcore.Networks.testnet;
var HDPrivateKey = bitcore.HDPrivateKey;
var explorers = require('bitcore-explorers');
var client = new explorers.Insight();
var hdPrivateKey = new HDPrivateKey('tprv8ZgxMBicQKsPd194pj9j68Cc5vTVKdQzDKmN8G5EEhvuct5bg2pifdAGGJZoJUQm9McBpvKQqTwfoLuvxgaVKJhtCLHFjG9MiJ4xeemMFyz');
var hdPublicKey = hdPrivateKey.hdPublicKey
console.log('###########');
console.log('HDPRV', hdPrivateKey)
console.log('HDPUB', hdPublicKey)
for (i = 1; i <= 1; i++) {
private = hdPrivateKey.derive(i).privateKey;
public = hdPublicKey.derive(i);
address = public.publicKey;
console.log('Private', private.toWIF());
console.log('Public', public.publicKey);
console.log('Address', address.toAddress());
}
client.getUnspentUtxos(address, function(err, utxos) {
console.log('UTXOs:', utxos);
var transaction = new bitcore.Transaction()
.from(utxos) // Feed information about what unspent outputs one can use
.to('n2PXLEzdBrRqg8esoVzYSxNNzLAZKrHkkW', 1000000) // Add an output with the given amount of satoshis
.change('mgKAD4Nm79EXVd8GbvvvFtZah8ZMEAHVJN')
.sign(private); // Signs all the inputs it can
console.log(transaction);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment