3

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

16WBguy6KVyTGnF4KX7Vmdx8ztj4wENh4W

and the message

bkawk

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

cont...

// 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()
            console.log(txId);

// Resolve the promise
            resolve(txRaw);

// Log the hex
            console.log(txRaw.toHex());
        } else{

// if there was an error reject the promise
            reject(error);
        };
    })

}); //-- END PROMISE
};// END FUNCTION

the above console.log is giving me this transaction hex

0100000001b4c1870d4e0c6928f40224f465ab7d2c3692fe29e4bc2cc5213776ff128de13f000000006b483045022100a954cdb05753fed2f8afc41619d66dde45e330b1aa75cd5a1d1a03b67392642702203bda25690dac67bed0117fd28ad30fc2cbc16aa778a3b37832aabba9939e344001210298e836ce7df5696bdce02742bb5d7a070b2e5b1ab3535001b71f3615c21c1b1dffffffff030000000000000000076a05626b61776bb80b0000000000001976a9143c5d9d2466274014c2db74dd4738116a193d142788acb80b0000000000001976a9143c5d9d2466274014c2db74dd4738116a193d142788ac00000000

which decoded looks like this

        {
        "lock_time":0,
        "size":242,
        "inputs":[
            {
                "prev_out":{
                    "index":0,
                    "hash":"3fe18d12ff763721c52cbce429fe92362c7dab65f42402f428690c4e0d87c1b4"
                },
                "script":"483045022100a954cdb05753fed2f8afc41619d66dde45e330b1aa75cd5a1d1a03b67392642702203bda25690dac67bed0117fd28ad30fc2cbc16aa778a3b37832aabba9939e344001210298e836ce7df5696bdce02742bb5d7a070b2e5b1ab3535001b71f3615c21c1b1d"
            }
        ],
        "version":1,
        "vin_sz":1,
        "hash":"926eeecb1fc28a34cb8ed14e1e6175ec9012af390b232e26d3c610c345abba47",
        "vout_sz":3,
        "out":[
            {
                "script_string":"OP_RETURN 626b61776b",
                "value":0,
                "script":"6a05626b61776b"
            },
            {
                "script_string":"OP_DUP OP_HASH160 3c5d9d2466274014c2db74dd4738116a193d1427 OP_EQUALVERIFY OP_CHECKSIG",
                "address":"16WBguy6KVyTGnF4KX7Vmdx8ztj4wENh4W",
                "value":3000,
                "script":"76a9143c5d9d2466274014c2db74dd4738116a193d142788ac"
            },
            {
                "script_string":"OP_DUP OP_HASH160 3c5d9d2466274014c2db74dd4738116a193d1427 OP_EQUALVERIFY OP_CHECKSIG",
                "address":"16WBguy6KVyTGnF4KX7Vmdx8ztj4wENh4W",
                "value":3000,
                "script":"76a9143c5d9d2466274014c2db74dd4738116a193d142788ac"
            }
        ]
        }

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?

https://blockchain.info/address/16WBguy6KVyTGnF4KX7Vmdx8ztj4wENh4W

Here is an example of a successful transaction made from Colu

https://blockchain.info/tx/d831fa05d6bbb2e939e42764945936ee7c23b96a46c173c9e8647d9fe4f0d485?show_adv=true

  • 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 Jun 10 '16 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? – Will-In-China Jun 10 '16 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 Jun 10 '16 at 14:00
0

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 – Will-In-China Jun 10 '16 at 11:26
  • and looking it up here webbtc.com/tx/… says it cant be found – Will-In-China Jun 10 '16 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 Jun 10 '16 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 – Will-In-China Jun 10 '16 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 Jun 10 '16 at 12:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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