Post
Topic
Board Service Discussion
Re: How to correctly push transaction?
by
DrSeuss
on 23/01/2017, 17:26:20 UTC
Thanks anyway man Smiley

Sadly I don't find any help online, the Repo's don't include info either. :/
So if anyone has more ideas, I'd be glad. Smiley

This is what I have
Code:
// Sign the transaction with keyPair of Sender
                        for (var i in transHashesNeeded){
                            tx.sign(parseInt(i), keyPair);
                        }

                        var transactionHex = tx.build().toHex()

                        // Request current BTC Price for $ & €
                        var decodedHex;

                        $.ajax({
                            url: "http://btc.blockr.io/api/v1/tx/decode",
                            type: "post",
                            data: {
                            hex: transactionHex
                            },
                            success: function(response) {
                                decodedHex = response;

                                document.getElementById('baseDiv').innerHTML += "

Decoded Hex: " + JSON.stringify(response);

                                $.ajax({
                                    url: "http://btc.blockr.io/api/v1/tx/push",
                                    type: "post",
                                    contentType: "application/json; charset=utf-8",
                                    dataType: "json",
                                    data: JSON.stringify({   
                                        hex: transactionHex
                                    }),
                                    success: function(response) {
                                        console.log("Transaction pushed. " + response);
                                    },
                                    error: function(xhr) {
                                        console.log(this);
                                        console.log("Failed to Push: " + xhr.responseText);
                                        console.log("Transaction Hash: " + transactionHex);
                                        console.log("This is pushed: " + this.data);
                                    }
                                });
                            },
                            error: function(xhr) {
                                console.log("Failed to decode Hex. -> " + xhr);
                            }
                        });
                    }             
                });

And this is the console output

Code:
Objectaccepts: Objectasync: truecontentType: "application/json; charset=utf-8"contents: Objectconverters: ObjectcrossDomain: truedata: "{"hex":"0100000001329e495a5e7dbb619ca84b3f1bc9ee0cca279f538b7ea0513a33be5ed46fe370000000006a473044022075b6372ed5febf7724613eddf7207fb5ed7b60b8c3f8d2cb77e76248c1f2daf102206edef165631bdf8455a5b486c0f7189ed80719c5ec726dccdecf3564fd59ae7901210250a251bd8365ee73a91fe09cb3477b400841c158a59874a8b041e7dff48412e5ffffffff0280969800000000001976a9142ca0f264fcffd0ceb34b109e1403a11ecacd73b288ac17db6d07000000001976a914251fafe412cdd9d4f32aabb8ea8858a97203016588ac00000000"}"dataType: "json"dataTypes: Array[2]error: (xhr)flatOptions: Objectglobal: truehasContent: trueisLocal: falsejsonp: "callback"jsonpCallback: ()processData: trueresponseFields: Objectsuccess: (response)type: "POST"url: "http://btc.blockr.io/api/v1/tx/push"xhr: ()__proto__: Object
(index):170 Failed to Push: {"status":"fail","data":"Could not push your transaction!","code":500,"message":"Did you sign your transaction?"}
(index):171 Transaction Hash: 0100000001329e495a5e7dbb619ca84b3f1bc9ee0cca279f538b7ea0513a33be5ed46fe370000000006a473044022075b6372ed5febf7724613eddf7207fb5ed7b60b8c3f8d2cb77e76248c1f2daf102206edef165631bdf8455a5b486c0f7189ed80719c5ec726dccdecf3564fd59ae7901210250a251bd8365ee73a91fe09cb3477b400841c158a59874a8b041e7dff48412e5ffffffff0280969800000000001976a9142ca0f264fcffd0ceb34b109e1403a11ecacd73b288ac17db6d07000000001976a914251fafe412cdd9d4f32aabb8ea8858a97203016588ac00000000
(index):172 This is pushed: {"hex":"0100000001329e495a5e7dbb619ca84b3f1bc9ee0cca279f538b7ea0513a33be5ed46fe370000000006a473044022075b6372ed5febf7724613eddf7207fb5ed7b60b8c3f8d2cb77e76248c1f2daf102206edef165631bdf8455a5b486c0f7189ed80719c5ec726dccdecf3564fd59ae7901210250a251bd8365ee73a91fe09cb3477b400841c158a59874a8b041e7dff48412e5ffffffff0280969800000000001976a9142ca0f264fcffd0ceb34b109e1403a11ecacd73b288ac17db6d07000000001976a914251fafe412cdd9d4f32aabb8ea8858a97203016588ac00000000"}

If you simply take the transactionHex and push it manually everything works perfectly fine.