Author

Topic: Empty error message in "broadcast" API function (but not in console) [SOLVED] (Read 95 times)

legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
Are you by any chance manually creating a string with "curly braces", "commas", etc. in it?

No strings are created by hand except for the address and amount argument supplied to "payto" command, which had always worked fine.

I directly supplied the return value of that to the "tx" argument of "signtransaction" (which also worked for some reason), who's return value I passed to "tx" argument to "broadcast" (this was where the error would occur)
legendary
Activity: 3472
Merit: 10611
Are you by any chance manually creating a string with "curly braces", "commas", etc. in it?

If yes, this was your mistake. When you want to create a JSON object it is always best to create a JSON object not a string by hand. There should be libraries for it in all languages. For example you define tx then set its value to a hexadecimal string. In the end you use the ToString or ConvertToString method on that object to convert it to a string and use that result to send to the server.

It probably means (and I'm just speculating) Electrum literally pushes your transaction to a server which then forwards it to a bitcoin node with the literal double quotes still inside.
Electrum "servers" are themselves full nodes, they receive your messages, parse the JSON and act accordingly.
legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
I am making HTTPS wrappers around a few Electrum commands, one of them being "broadcast". I already have methods for both "payto" and "signtransaction" that work correctly. But when I try to call "broadcast" from the API, I get an error back from Electrum but with an empty message string and code "1":

Code:
{"id":"curltext","jsonrpc":"2.0","error":{"code":1,"message":""}}

I'm making a POST request with application/x-www-form-urlencoded type with the following body:

Code:
{"jsonrpc":"2.0","id":"curltext","method":"broadcast","params":{"tx": tx}} // where tx is supplied from "signtransaction"

Strangely, this method works fine when I call it from the command line.

Without the error message, I'm at a loss at what could possibly be the problem.

It is definitely not an error in my HTTPS setup because another network function (getinfo) returns successfully and shows I'm connected to an electrum server.

So it is clearly a problem with the "broadcast" command (in particular, some exception was raised somewhere inside it, without the error message, so that narrows the problem down a little. The Timeout exception is one such possibility but this is practically impossible to occur on a 1Gbps line).

Electrum version: 4.1.5



EDIT: Apparently, I found that the reason the method was failing so mysteriously was because there were literal double quotes in the tx at the beginning and end. I had plainly reused the output of "signtransaction", which is strange because the "signtransaction" RPC handles the result of the "payto" RPC - which also has double quotes around it - just fine.

It probably means (and I'm just speculating) Electrum literally pushes your transaction to a server which then forwards it to a bitcoin node with the literal double quotes still inside.

So, for anyone else who happens across this thread in the future, always remove the quotes from your tx string (using array slices) before broadcasting it with Electrum.  Smiley
Jump to: