Send raw bitcoin transaction with js?

I am trying to create a small web application (for educational purposes only) where I can click on a button and it will send some bitcoin from (my own) bitcoin wallet A to bitcoin wallet B. I was able to learn a thing or two about bitcoin. blockchain and figure out how to make a raw bitcoin transaction like this:

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 generated check to a website like https://blockr.io/tx/push it will successfully execute a bitcoin transaction, but I would like to know if it can be automated to push a raw transaction with js? Thanks for reading:)

+3


source to share


1 answer


Using bitcore explorer :

Insight is a simple agent for executing queries against the Insight blockchain explorer. The default servers are https://insight.bitpay.com and https://test-insight.bitpay.com hosted by BitPay Inc. You can (and we highly recommend you do) run your own insight server. For more info, head to https://github.com/bitpay/insight-api



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
  }
});

      

0


source







All Articles