Bitcoin Forum
May 25, 2024, 08:42:07 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: [solved] Problem with transaction from the command line  (Read 112 times)
darkv0rt3x (OP)
Hero Member
*****
Offline Offline

Activity: 1218
Merit: 660


I rather die on my feet than to live on my knees


View Profile
October 11, 2020, 03:43:07 PM
Last edit: October 11, 2020, 08:11:00 PM by darkv0rt3x
Merited by Heisenberg_Hunter (1)
 #1

Hello.

I'm here again to ask for help. This time is about a raw transaction I created an that I can't broadcast to the network.

OS and other info:

I'm using Debian Buster
Bitcoin Core RPC client version v0.20.1 (online full node)
Bitcoin Core RPC client version v0.18.1 (offline node)


I use an online node to create the transaction and to broadcast it. And I use one other node, this one offline, to sign the transaction.
The command used to create the transaction was:

Code:
bitcoin-cli createrawtransaction "[{\"txid\":\"xxxxxxxxxxxxxxxxxx11111111111111111111111xxxxxxxxxxxxxxxxxxxxxx\", \"vout\":0}]" "[{\"xxxxxxxxdestination_address_herexxxxxxxx\":0.11223344}, {\"xxxxxxxxchange_address_herexxxxxxxx\":0.55667788}]"

Note: hashes, addresses an amounts are fictional, of course. If this info is really necessary I may provide it. Also, the hashes that repeat over commands, I meant to make them the same here so that people know that I used this info here AND there. Like in the case of xxxxxxxxxxxxxxxxxx11111111111111111111111xxxxxxxxxxxxxxxxxxxxxx that was used in these two first commands.

The command returned an hash. No errors here, so I proceeded for the signing.
In the first place, I copied the hash from the command signrawtransactionwithwallet, from the online node, to the offline node.

Then I used signrawtransactionwithwallet to sign the transaction.
Code:
bitcoin-cli signrawtransactionwithwallet "xxxxxxxxxxxxxxx_hash_of_the_createrawtransaction_command_here_xxxxxxxxxxxxxxx" "[{\"txid\":\"xxxxxxxxxxxxxxxxxx11111111111111111111111xxxxxxxxxxxxxxxxxxxxxx\", \"vout\":0, \"scriptPubKey\":\"scriptPubKey_obtained_from_the_source_address\", \"amount\":0.99001122}]"

This command also returned an hash. I copied it to the online node and tried to broadcast it to the network with the following command:
Code:
bitcoin-cli sendrawtransaction "xxxxxxxxxxxxx_hash_returned_from_the_signrawtransactionwithwallet_command_xxxxxxxxxxxxx"

The return message was an error:
Quote
error code: -26
error message:
non-mandatory-script-verify-flag (Witness program hash mismatch)



I though this was due to the fact that I signed the transaction with signrawtransactionwithwallet command, so I went again to the offline node to try to sign it using signrawtransactionwithkey.
The command I used was:

Code:
bitcoin-cli signrawtransactionwithkey "xxxxxxxxxxxxxxx_hash_of_the_createrawtransaction_command_here_xxxxxxxxxxxxxxx" "[\"xxxxxxxxxxxxx_source_address_private_key_here_xxxxxxxxxxxxx\"]"

This time I got this JSON object, returning another error:

Code:
{
  "hex": "xxxxxxxxxxxxxxx_hash_of_the_createrawtransaction_command_here_xxxxxxxxxxxxxxx",
  "complete": false,
  "errors": [
    {
      "txid": "xxxxxxxxxxxxxxxxxx11111111111111111111111xxxxxxxxxxxxxxxxxxxxxx",
      "vout": 0,
      "witness": [
      ],
      "scriptSig": "",
      "sequence": 1122334455,
      "error": "Input not found or already spent"
    }
  ]
}


So, what did I do wrong and what do I need to do to make this work?

Bitcoin is energy. Bitcoin is freedom
I rather die on my feet than living on my knees!
AdolfinWolf
Legendary
*
Offline Offline

Activity: 1946
Merit: 1427


View Profile
October 11, 2020, 05:30:24 PM
Last edit: October 11, 2020, 06:03:55 PM by AdolfinWolf
 #2

Second error; you most likely didn't specify the inputs. The offline node has no idea what the inputs are as he does probably does not have an updated UTXO set. See => https://bitcoin-rpc.github.io/en/doc/0.17.0/rpc/rawtransactions/signrawtransactionwithkey/

First error, I'm not really sure. What address type are you spending from (input?!)?

If P2WSH  || P2SH, you need to include the redeemscript when signing.

Code:
bitcoin-cli signrawtransactionwithwallet "xxxxxxxxxxxxxxx_hash_of_the_createrawtransaction_command_here_xxxxxxxxxxxxxxx" "[{\"txid\":\"xxxxxxxxxxxxxxxxxx11111111111111111111111xxxxxxxxxxxxxxxxxxxxxx\", \"vout\":0, \"scriptPubKey\":\"scriptPubKey_obtained_from_the_source_address\", \"amount\":0.08752663}]"
Are you sure this is right? you're using a 0.08752663 BTC input to spend ~ 0.11223344 + 0.55667788 ?

Edit: I'm unable to reproduce your error. [error code: -26] means that it is rejected by the network for w/e reason. I think that if you want this to get solved, we're gonna need more details.

darkv0rt3x (OP)
Hero Member
*****
Offline Offline

Activity: 1218
Merit: 660


I rather die on my feet than to live on my knees


View Profile
October 11, 2020, 05:37:01 PM
Last edit: October 11, 2020, 06:01:51 PM by darkv0rt3x
 #3

Second error; you most likely didn't specify the inputs. The offline node has no idea what the inputs are as he does probably does not have an updated UTXO set. See => https://bitcoin-rpc.github.io/en/doc/0.17.0/rpc/rawtransactions/signrawtransactionwithkey/

First error, I'm not really sure. What address type are you spending from (input?!)?

If P2WSH  || P2SH, you need to include the redeemscript when signing.

Code:
bitcoin-cli signrawtransactionwithwallet "xxxxxxxxxxxxxxx_hash_of_the_createrawtransaction_command_here_xxxxxxxxxxxxxxx" "[{\"txid\":\"xxxxxxxxxxxxxxxxxx11111111111111111111111xxxxxxxxxxxxxxxxxxxxxx\", \"vout\":0, \"scriptPubKey\":\"scriptPubKey_obtained_from_the_source_address\", \"amount\":0.08752663}]"
Are you sure this is right? you're using a 0.08752663 BTC input to spend ~ 0.11223344 + 0.55667788 ?

Both addresses are bech32. Sorry for not specifying.

The values are random.
Yes, the offline node was never online, so it doesn't know about the state of the utxo's.

The math I did was:
To the amount I had in this address, I subtracted the amount I wanted to send. Then, also subtracted a fee of about 4.6 sats / vByte (around 521 sats). Then, the remaining BTC was sent to the change address.

Bitcoin is energy. Bitcoin is freedom
I rather die on my feet than living on my knees!
AdolfinWolf
Legendary
*
Offline Offline

Activity: 1946
Merit: 1427


View Profile
October 11, 2020, 06:13:50 PM
Last edit: October 11, 2020, 06:35:39 PM by AdolfinWolf
 #4

To the amount I had in this address, I subtracted the amount I wanted to send. Then, also subtracted a fee of about 4.6 sats / vByte (around 521 sats). Then, the remaining BTC was sent to the change address.
With "In this address" - are you referring to the prevtxsOut amount specification?

It really should look like this:
Code:
bitcoin-cli signrawtransactionwithwallet "hexstring" "[{\"txid\":\"input_Txid\", \"vout\":input_vout, \"scriptPubKey\":\"scriptPubKey_obtained_from_the_source_address\", \"amount\":full input amount}]"

in createrawtransaction it should be amount_prev_input - fee (if we're using a single input) === (address you want to spend to)+ change, so i guess what you're saying makes sense (?).

(Not to mention the error for wrong amounts either in createrawtransaction or the specification in prevtxOuts is bad-txns-in-belowout?)

I can't offer any solution. The only way i'm able to reproduce Witness program hash mismatch is @ walletsigning, as a result of not importing the private key, which doesn't seem to be your issue, as you get this when broadcasting..

darkv0rt3x (OP)
Hero Member
*****
Offline Offline

Activity: 1218
Merit: 660


I rather die on my feet than to live on my knees


View Profile
October 11, 2020, 07:26:22 PM
Last edit: October 11, 2020, 08:42:50 PM by darkv0rt3x
 #5

Ok, lets put in some numbers.

In the source address I have a single input utxo. It holds 0.5BTC.

I want to send to the destination address, 0.002 BTC.

And I want to pay about 521 sats, that at 9600€, is about 0.5€. That turned out to be about 4.6 sats/vByte.

So, the amount to send would be 0.002.
The change address would get -> 0.5 - 0.002 - 0.00000521 = 0.49799479

So the command would be:

Code:
bitcoin-cli createnewtransaction "[{\"txid\":\"txid_from_source_address\", \"vout\":0}]" "[{\"destination_address\":0.002}, {\"change_address\":0.49799479}]"

This returns the hash
Quote
000000aaabbbcccetc000000

Then in my offline node I do (or did):

Code:
bitcoin-cli signrawtransactionwithwallet "000000aaabbbcccetc000000" "[{\"txid\":\"txid_from_source_address\", \"vout\":0, \"scriptPubKey\":\"00000_scriptPubKey_from_source_address_00000\", \"amount\":0.5}]"

Isn't it correct this way?


Bitcoin is energy. Bitcoin is freedom
I rather die on my feet than living on my knees!
darkv0rt3x (OP)
Hero Member
*****
Offline Offline

Activity: 1218
Merit: 660


I rather die on my feet than to live on my knees


View Profile
October 11, 2020, 08:10:31 PM
 #6

Ok, somehow I managed to repeat the signrawtransactionwithkey and broadcast it to the network.

Next time I will try with signrawtransactionwithwallet command!

I have no idea what went wrong the first time with signrawtransactionwithwallet nor with the 2nd attempt with signrawtransactionwithkey. Probably some parameter in the wrong place or missing.

As they say, the 3rd time it's "make it, or break it"!

Thanks everyone that helped!

Bitcoin is energy. Bitcoin is freedom
I rather die on my feet than living on my knees!
AdolfinWolf
Legendary
*
Offline Offline

Activity: 1946
Merit: 1427


View Profile
October 11, 2020, 08:25:02 PM
 #7

I have no idea what went wrong the first time with signrawtransactionwithwallet nor with the 2nd attempt with signrawtransactionwithkey. Probably some parameter in the wrong place or missing.
I'm pretty sure the second time you didn't specify the prevTxouts, (which is also required for signrawtransactionwithkey, https://bitcoin-rpc.github.io/en/doc/0.17.0/rpc/rawtransactions/signrawtransactionwithkey/, if you use an offline node that is.)

I'm guessing the first attempt you broadcasted to a node which saw your transaction as non-standard? but perhaps someone else can clarify this a bit further, as I'd imagine you (=> bitcoin core) don't just broadcast to a single node.

darkv0rt3x (OP)
Hero Member
*****
Offline Offline

Activity: 1218
Merit: 660


I rather die on my feet than to live on my knees


View Profile
October 11, 2020, 08:36:24 PM
 #8

I have no idea what went wrong the first time with signrawtransactionwithwallet nor with the 2nd attempt with signrawtransactionwithkey. Probably some parameter in the wrong place or missing.
I'm pretty sure the second time you didn't specify the prevTxouts, (which is also required for signrawtransactionwithkey, https://bitcoin-rpc.github.io/en/doc/0.17.0/rpc/rawtransactions/signrawtransactionwithkey/, if you use an offline node that is.)

I'm guessing the first attempt you broadcasted to a node which saw your transaction as non-standard? but perhaps someone else can clarify this a bit further, as I'd imagine you (=> bitcoin core) don't just broadcast to a single node.

Yeah, I could dig in into my offline node command history and try to figure it out but I think it's not worth now.
I'm not sure what those prevtxouts would be. There is only one utxo in the source address, so that was the only one I could use. If it's prevTxout or prevTxin, I guess it depends from which perspective you see it. If from the source perspective or from the destination perspective. I don't know. This part is a bit ambiguous to me. The prev, next, in and out terms, may get pretty confusing.

Well, about the 1st attempt broadcasting, I don't think other nodes might have seen it as a non standard transaction, because the error was quite instantaneous. So, I believe more that the command figured it out from the hash key I provided to the command. I mean, the hash key is just a bunch of information hashed. So, the command figured that something was wrong. But I'm also just speculating.

Bitcoin is energy. Bitcoin is freedom
I rather die on my feet than living on my knees!
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!