DrSeuss (OP)
Newbie
Offline
Activity: 26
Merit: 0
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
January 23, 2017, 12:19:32 PM |
|
What's up! ![Wink](https://bitcointalk.org/Smileys/default/wink.gif) I'm currently coding a Bitcoin-Transaction-System on my Website. (via bitcoinjs-lib) Now I'm kinda stuck with pushing the transaction. Can anyone tell me what exactly I have to push? It's weird because I generate a Hex which works fine if I push it manually via http://tbtc.blockr.io/documentation/api But as soon as I try to push via code the whole thing just dies. Failed to push transaction. -> {"status":"error","data":"TX is missing","code":400,"message":"Please see API documentation on how to POST tx hex as json."} $.ajax({ url: "http://btc.blockr.io/api/v1/tx/decode", type: "post", data: { hex: transactionHex }, success: function(response) { decodedHex = response; console.log(decodedHex); document.getElementById('baseDiv').innerHTML += "<br /><br />Decoded Hex: " + transactionHex; }, error: function(xhr) { console.log("Failed to decode Hex. -> " + xhr); } });
$.ajax({ url: "http://btc.blockr.io/api/v1/tx/push", type: "post", data: { hex: decodedHex }, success: function(response) { console.log("Transaction pushed. " + response); }, error: function(xhr) { console.log("Failed to push transaction. -> " + xhr.responseText); } }); Can anyone give me a few pointers what could be the problem? ![Smiley](https://bitcointalk.org/Smileys/default/smiley.gif) Thanks so much! <3 Cheerz~
|
|
|
|
DrSeuss (OP)
Newbie
Offline
Activity: 26
Merit: 0
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
January 23, 2017, 01:46:57 PM |
|
I just tried pushing it manually and actually got an error, maybe this helps:
PUSH TRANSACTION ERROR: 16: MANDATORY-SCRIPT-VERIFY-FLAG-FAILED (SCRIPT FAILED AN OP_EQUALVERIFY OPERATION)
|
|
|
|
DrSeuss (OP)
Newbie
Offline
Activity: 26
Merit: 0
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
January 23, 2017, 02:37:03 PM |
|
I just tried pushing it manually and actually got an error, maybe this helps:
PUSH TRANSACTION ERROR: 16: MANDATORY-SCRIPT-VERIFY-FLAG-FAILED (SCRIPT FAILED AN OP_EQUALVERIFY OPERATION)
I found out that I had something mixed up, but sadly I still can't push Failed to Push: {"status":"error","data":"TX is missing","code":400,"message":"Please see API documentation on how to POST tx hex as json."} Does anyone know why this happens? I can push manually but not via code, this is driving me insane. ;(
|
|
|
|
DrSeuss (OP)
Newbie
Offline
Activity: 26
Merit: 0
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
January 23, 2017, 03:00:24 PM |
|
This is how I post my request to the API { "hex":{ "txid":"3fc25ec159a031c1c8b643a9ef083dbf4011f91b2eff6952b59fa239dccfba94", "size":226, "version":1, "locktime":0, "vin":[ { "txid":"97cf8b040250cee0b30ea61bd2dbbc2425a4b50231477bd8e459ada9e2a98ab2", "vout":1, "scriptSig":{ "asm":"3045022100c7d4fcfa0b8880766e1ef89516236667be59c1a087702df263515a40f84f51b502205f84c36551bf8ad8a3a54e715241181b835720d56d6b5816b172409dd4bab1e3[ALL] 0250a251bd8365ee73a91fe09cb3477b400841c158a59874a8b041e7dff48412e5", "hex":"483045022100c7d4fcfa0b8880766e1ef89516236667be59c1a087702df263515a40f84f51b502205f84c36551bf8ad8a3a54e715241181b835720d56d6b5816b172409dd4bab1e301210250a251bd8365ee73a91fe09cb3477b400841c158a59874a8b041e7dff48412e5" }, "sequence":4294967295 } ], "vout":[ { "value":0.1, "n":0, "scriptPubKey":{ "asm":"OP_DUP OP_HASH160 2ca0f264fcffd0ceb34b109e1403a11ecacd73b2 OP_EQUALVERIFY OP_CHECKSIG", "hex":"76a9142ca0f264fcffd0ceb34b109e1403a11ecacd73b288ac", "reqSigs":1, "type":"pubkeyhash", "addresses":[ "154yYDzR6NXTrGyaZnM6d8zpB9PiDBjGGG" ] } }, { "value":1.5994576, "n":1, "scriptPubKey":{ "asm":"OP_DUP OP_HASH160 251fafe412cdd9d4f32aabb8ea8858a972030165 OP_EQUALVERIFY OP_CHECKSIG", "hex":"76a914251fafe412cdd9d4f32aabb8ea8858a97203016588ac", "reqSigs":1, "type":"pubkeyhash", "addresses":[ "14PHxkkBb3PxFGNPBiWTWKKiYSA7xWJgC7" ] } } ] } } But the JSON that get's parsed by decoding the hex on the website itself looks different, why that? Please note that the api want's me to give the tx json they key "hex" { "Version":"1", "LockTime":"0", "Vin":[ { "TxId":"97cf8b040250cee0b30ea61bd2dbbc2425a4b50231477bd8e459ada9e2a98ab2", "Vout":"1", "ScriptSig":{ "Asm":"3045022100c7d4fcfa0b8880766e1ef89516236667be59c1a087702df263515a40f84f51b502205f84c36551bf8ad8a3a54e715241181b835720d56d6b5816b172409dd4bab1e3[ALL] 0250a251bd8365ee73a91fe09cb3477b400841c158a59874a8b041e7dff48412e5", "Hex":"483045022100c7d4fcfa0b8880766e1ef89516236667be59c1a087702df263515a40f84f51b502205f84c36551bf8ad8a3a54e715241181b835720d56d6b5816b172409dd4bab1e301210250a251bd8365ee73a91fe09cb3477b400841c158a59874a8b041e7dff48412e5" }, "CoinBase":null, "TxInWitness":null, "Sequence":"4294967295" } ], "Vout":[ { "Value":0.1, "N":0, "ScriptPubKey":{ "Asm":"OP_DUP OP_HASH160 2ca0f264fcffd0ceb34b109e1403a11ecacd73b2 OP_EQUALVERIFY OP_CHECKSIG", "Hex":"76a9142ca0f264fcffd0ceb34b109e1403a11ecacd73b288ac", "ReqSigs":1, "Type":"pubkeyhash", "Addresses":[ "mjavqH5PuPxidPTCHMKUT4D938zR7kat3R" ] } }, { "Value":1.5994576, "N":1, "ScriptPubKey":{ "Asm":"OP_DUP OP_HASH160 251fafe412cdd9d4f32aabb8ea8858a972030165 OP_EQUALVERIFY OP_CHECKSIG", "Hex":"76a914251fafe412cdd9d4f32aabb8ea8858a97203016588ac", "ReqSigs":1, "Type":"pubkeyhash", "Addresses":[ "miuFFoqAQ4qD2NqzuHUqLEY3QRkptMcHMu" ] } } ], "TxId":"3fc25ec159a031c1c8b643a9ef083dbf4011f91b2eff6952b59fa239dccfba94" }
|
|
|
|
Coding Enthusiast
Legendary
Offline
Activity: 1040
Merit: 2785
Bitcoin and C♯ Enthusiast
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
January 23, 2017, 03:20:07 PM Last edit: January 23, 2017, 03:40:35 PM by Coding Enthusiast |
|
I don't understand the programming language you are using but I think your problem is that you are passing a wrong string as your hex parameter when you want to push. When you call the url .../decode and take the response and put it in the decodedHex variable, then you are pushing decodedHex (which is a JSON) to .../push url. If I understood your code correctly, that is a wrong approach.
In the second part you have to push a Raw transaction JSON like this {"hex":"TX_HASH"} not the whole JSON. Take your transactionHex variable from the first part (line 5) and use that to push.
|
|
|
|
DrSeuss (OP)
Newbie
Offline
Activity: 26
Merit: 0
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
January 23, 2017, 03:24:23 PM |
|
POST http://btc.blockr.io/api/v1/tx/push 400 (Bad Request) send @ jquery.min.js:4 ajax @ jquery.min.js:4 success @ (index):159 i @ jquery.min.js:2 fireWith @ jquery.min.js:2 z @ jquery.min.js:4 (anonymous) @ jquery.min.js:4 (index):169 Failed to Push: {"status":"error","data":"TX is missing","code":400,"message":"Please see API documentation on how to POST tx hex as json."} (index):170 Transaction Hash: 010000000194bacfdc39a29fb55269ff2e1bf91140bf3d08efa943b6c8c131a059c15ec23f01000000694630430220691210387a5a5897afedf546e42a482265b2be96ba36f5e2624168f4d94df8d7021f587c9b670089d81f0aee897364aa6e3320f0a9235e5f70924bbaee287f0f6d01210250a251bd8365ee73a91fe09cb3477b400841c158a59874a8b041e7dff48412e5ffffffff0280969800000000001976a9142ca0f264fcffd0ceb34b109e1403a11ecacd73b288ac00b7ef08000000001976a914251fafe412cdd9d4f32aabb8ea8858a97203016588ac00000000 (index):171 This is pushed: {"hex":"010000000194bacfdc39a29fb55269ff2e1bf91140bf3d08efa943b6c8c131a059c15ec23f01000000694630430220691210387a5a5897afedf546e42a482265b2be96ba36f5e2624168f4d94df8d7021f587c9b670089d81f0aee897364aa6e3320f0a9235e5f70924bbaee287f0f6d01210250a251bd8365ee73a91fe09cb3477b400841c158a59874a8b041e7dff48412e5ffffffff0280969800000000001976a9142ca0f264fcffd0ceb34b109e1403a11ecacd73b288ac00b7ef08000000001976a914251fafe412cdd9d4f32aabb8ea8858a97203016588ac00000000"} This is what I get when I try to do it with the transactionHex :/
|
|
|
|
Coding Enthusiast
Legendary
Offline
Activity: 1040
Merit: 2785
Bitcoin and C♯ Enthusiast
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
January 23, 2017, 03:43:08 PM |
|
I fixed a mistake in my comment, you have to push what you have in the last line not a string, and not the whole JSON you have in above comment. The JSON is a one parameter object with this format: {"hex":"TX_HASH"} Replace TX_HASH with the transaction hash (the line before last, the string starting with 010000000194)
|
|
|
|
DrSeuss (OP)
Newbie
Offline
Activity: 26
Merit: 0
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
January 23, 2017, 03:48:50 PM |
|
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; console.log(decodedHex); pushHex = JSON.stringify(decodedHex.data.tx); pushHex2 = JSON.parse(pushHex); document.getElementById('baseDiv').innerHTML += "<br /><br />Decoded Hex: " + JSON.stringify(response);
$.ajax({ url: "https://testnet-api.smartbit.com.au/v1/blockchain/pushtx", type: "post", data2: { hex: transactionHex }, success: function(response) { console.log("Transaction pushed. " + response); }, error: function(xhr) { console.log("Failed to Push: " + xhr.responseText); console.log("Transaction Hash: " + transactionHex); console.log("This is pushed: " + JSON.stringify(this.data2)); } }); }, error: function(xhr) { console.log("Failed to decode Hex. -> " + xhr); } }); I don't really understand what you mean but as you see I'm using the transactionHash as a parameter. ![Shocked](https://bitcointalk.org/Smileys/default/shocked.gif) {"hex":"010000000194bacfdc39a29fb55269ff2e1bf91140bf3d08efa943b6c8c131a059c15ec23f01000000694630430220691210387a5a5897afedf546e42a482265b2be96ba36f5e2624168f4d94df8d7021f587c9b670089d81f0aee897364aa6e3320f0a9235e5f70924bbaee287f0f6d01210250a251bd8365ee73a91fe09cb3477b400841c158a59874a8b041e7dff48412e5ffffffff0280969800000000001976a9142ca0f264fcffd0ceb34b109e1403a11ecacd73b288ac00b7ef08000000001976a914251fafe412cdd9d4f32aabb8ea8858a97203016588ac00000000"} is what's beeing pushed, with hex beeing the key and the transactionHash as parameter, what is my mistake? I feel so stupid right now ![Roll Eyes](https://bitcointalk.org/Smileys/default/rolleyes.gif)
|
|
|
|
Coding Enthusiast
Legendary
Offline
Activity: 1040
Merit: 2785
Bitcoin and C♯ Enthusiast
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
January 23, 2017, 04:04:46 PM |
|
The problem is that I don't know anything about this language you are using. Try adding a header indicating your contentType and set it to application/jsonThis is what I do in C# using (HttpClient client = new HttpClient()) { string hex = "010000000194bacf......"; string Json = "{\"hex\":\"" + hex + "\"}"; string url = "http://btc.blockr.io/api/v1/tx/push"; HttpContent content = new StringContent(Json); content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
var respond = await client.PostAsync(url, content);
var result = await respond.Content.ReadAsStringAsync(); }
A quick and dirty work.
|
|
|
|
DrSeuss (OP)
Newbie
Offline
Activity: 26
Merit: 0
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
January 23, 2017, 04:14:57 PM |
|
I'm using Javascript. $.ajax({ url: "http://btc.blockr.io/api/v1/tx/push", type: "post", contentType: "application/json; charset=utf-8", dataType: "json", data2: { hex: transactionHex }, success: function(response) { console.log("Transaction pushed. " + response); }, error: function(xhr) { console.log("Failed to Push: " + xhr.responseText); console.log("Transaction Hash: " + transactionHex); console.log("This is pushed: " + JSON.stringify(this.data2)); } }); I now declared that I will send a json but.. This is pushed: "{\"hex\":\"010000000194bacfdc39a29fb55269ff2e1bf91140bf3d08efa943b6c8c131a059c15ec23f01000000694630430220691210387a5a5897afedf546e42a482265b2be96ba36f5e2624168f4d94df8d7021f587c9b670089d81f0aee897364aa6e3320f0a9235e5f70924bbaee287f0f6d01210250a251bd8365ee73a91fe09cb3477b400841c158a59874a8b041e7dff48412e5ffffffff0280969800000000001976a9142ca0f264fcffd0ceb34b109e1403a11ecacd73b288ac00b7ef08000000001976a914251fafe412cdd9d4f32aabb8ea8858a97203016588ac00000000\"}" it fails ![Cry](https://bitcointalk.org/Smileys/default/cry.gif)
|
|
|
|
|
DrSeuss (OP)
Newbie
Offline
Activity: 26
Merit: 0
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
January 23, 2017, 05:26:20 PM Last edit: January 23, 2017, 05:51:20 PM by DrSeuss |
|
Thanks anyway man ![Smiley](https://bitcointalk.org/Smileys/default/smiley.gif) 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](https://bitcointalk.org/Smileys/default/smiley.gif) This is what I have // 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 += "<br /><br />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 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.
|
|
|
|
moonpie45
Newbie
Offline
Activity: 55
Merit: 0
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
January 24, 2017, 04:53:41 AM |
|
I would suggest that you run a full node (with pruning), and have your website send transactions to the network via your node.
In addition to your problem with blockr.io's API, with your current setup, you are risking that you will be unable to push any transactions when any part of the chain between you --> blockr.io --> blockr.io's node --> the rest of the network is broken.
You can setup your node so that it will delete the portion of the blockchain that goes back more than x MB (the default setting is 300 MB, but you can reduce this), and I believe you can change your node's settings so that it will only listen for new blocks (and not unconfirmed transactions), while still being able to relay new transactions that you wish to broadcast.
|
|
|
|
|