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":
{"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:
{"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.