Saturday, 15 April 2017

Send raw bitcoin transaction with js?

I'm trying to make a little web app (just for learning purposes), where I can push on a button, and it will send some bitcoin from (my own) bitcoin wallet A to bitcoin wallet B. I've managed to learn some stuff about bitcoin, the blockchain, and figured out how to make a raw bitcoin transaction like so:

var bitcoin = require('bitcoinjs-lib');

var keyPair = bitcoin.ECPair.fromWIF('****************************');
var tx = new bitcoin.TransactionBuilder();

tx.addInput('****************************', 0);
tx.addOutput('****************************', 546);
tx.sign(0, keyPair);

console.log(tx.build().toHex());
generatedhash = tx.build().toHex();

If I take the generatedhash to a website like https://blockr.io/tx/push it will succesfully do the bitcoin transaction, but I'd like to know if its possible to automate pushing the raw transaction using js as well? Thanks for reading :)



via Pazzle

No comments:

Post a Comment