0 votes
1 view
in Blockchain by (7k points)

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 :)

1 Answer

0 votes
by (14.5k points)

Use these lines of code for pushing the raw transaction using js: 

var Insight = require('bitcore-explorers').Insight;

var insight = new Insight();

insight.broadcast(tx, function(err, returnedTxId) {

  if (err) {

    // Handle errors...

  } else {

    // Mark the transaction as broadcasted

  }

});

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...