So the below is the function I'm running. I'm sending in the key for this bitcoin address


and the message


to this function

// Require the packages that we need.

var bitcoin = require('bitcoinjs-lib');
var request = require('request');
var blockchain = require('blockchain.info');
var blockexplorer = require('blockchain.info/blockexplorer');

// Export the module and pass in the message and the WIF
exports.opReturn = function (message, WIF) {

// Setup the new promise
return new Promise(function(resolve, reject) {    

// Set the network to the main net not test
    var network = bitcoin.networks.mainnet;

 // Generate the keypair
    var keyPair = bitcoin.ECPair.fromWIF(WIF);

// Get the address from the key pair
    var address = keyPair.getAddress();

// Ask blockchain.info for all the unspent transactions 
    var url = 'https://blockchain.info/id/unspent?active='+address;
    request(url, function (error, response, body) {

// Check the request didn't error and we got a 200 ok back
        if (!error && response.statusCode == 200) {

// Parse the results
            var body = JSON.parse(body);

// Build a new transaction
            var tx = new bitcoin.TransactionBuilder(network);


// Buffer the message into hex
            var data = new Buffer(message);

// Prepare the message
            var dataScript = bitcoin.script.nullDataOutput(data);

// I Suspect there is problems here!!
            var unspent = body.unspent_outputs[0].tx_hash_big_endian;

// Add the unspent tx to the output                
            tx.addInput(unspent, 0);

// Add the unspent transaction to the first output              
            tx.addOutput(dataScript, 0);

// Add our address to the 1st output - Must I use another address or no?
            tx.addOutput(address, 1000);

// Add our address to the 2nd output - Must I use another address here too?
            tx.addOutput(address, 1000);

// Sign the transaction
            tx.sign(0, keyPair);

// Convert to hex
            var txRaw = tx.build().toHex();

            var txId = txRaw.getId()

// Resolve the promise

// Log the hex
        } else{

// if there was an error reject the promise

}); //-- END PROMISE

the above console.log is giving me this transaction hex


which decoded looks like this

                "script_string":"OP_RETURN 626b61776b",
                "script_string":"OP_DUP OP_HASH160 3c5d9d2466274014c2db74dd4738116a193d1427 OP_EQUALVERIFY OP_CHECKSIG",
                "script_string":"OP_DUP OP_HASH160 3c5d9d2466274014c2db74dd4738116a193d1427 OP_EQUALVERIFY OP_CHECKSIG",

Pushing it to https://blockchain.info/pushtx returns...

None Standard Script Output OP_RETURN 626b61776b

And pushing here http://blockr.io/tx/push results in

There was an error pushing your transaction to network!

Did you sign your transaction? Is this double spend? Have you already sent this transaction?

but then when I check it here I don't see the transaction. Any Ideas?


Here is an example of a successful transaction made from Colu


  • You should probably edit the title to be the actual question, rather than the question's general topic. It would also be nice if the question itself was a little more specific, rather than just "here's my code, tell me what's wrong". Narrow your question down to a specific, identified problem, and you are more likely to get better answers.
    – Jestin
    Commented Jun 10, 2016 at 13:43
  • Thank you @jestin for the kind suggestion, the answer to the problem was unknown at the time of writing and as you can see I detailed the issue and where I thought the problems may be as best as I could. Please can you make a suggestions for the better title? Commented Jun 10, 2016 at 13:52
  • Something like "Invalid transaction created with bitcoinjs-lib" might be better. I don't think you had any reason to believe the Promise was the problem, since you were obviously resolving the raw transaction. That word just made it confusing which part you were asking about.
    – Jestin
    Commented Jun 10, 2016 at 14:00

1 Answer 1


the first (but not the last) error is:

your utxo 3fe1...1b4:0 has 3000 satoshi but the sum of your outputs is 6000 satoshi

  • Nice spotting! I have now reduced each to 1000 and now get no error from blockr but instead get.... Your transaction id is: 801d6fb0cbf920831973a3888f57fcac1fa76ba1642c804d94d3b213522dacd2 Commented Jun 10, 2016 at 11:26
  • and looking it up here webbtc.com/tx/… says it cant be found Commented Jun 10, 2016 at 11:32
  • 1
    (1) webbtc does not show unconfirmed transactions (2) the fee for your transaction is very small (3) the output values of 1000 satoshi are 'dust' (4) blockchain.info does not accept/show unconfirmed transactions with op_return scriptsigs.... aaaaaand everything else is quite fine! your transaction is valid!
    – amaclin
    Commented Jun 10, 2016 at 11:44
  • 1) I just need to wait for confirmation? 2) The transaction is small and i guess I will need to wait a long time? how long? 3) 1000 satoshi is commonly called "Dust" thank you and well noted. 4) blockchain.info I wont be using anymore Commented Jun 10, 2016 at 11:50
  • (1) it depends of your goal. usually I do not wait or even think about such small values (2) may be a hour, may be a day, may be a year (3) there is no consensus value for "dust". (4) up to you
    – amaclin
    Commented Jun 10, 2016 at 12:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.