I am following this tutorial, which says to use signrawtransaction. However, I get:

error code: -32
error message:
signrawtransaction was removed in v0.18.
Clients should transition to using signrawtransactionwithkey and signrawtransactionwithwallet

The API call in the tutorial shows this:

$ signedtx2=$(bitcoin-cli -named signrawtransaction hexstring=$rawtxhex2 | jq -r '.hex')

How do I do that same thing using the new signrawtransactionwithkey API? I started by generating a 256-bit private key:


Now I'm not sure what to do. I guess I am to do something like this, but not sure exactly how to define it using CLI variables and such to make sure it's going to work.

signrawtransactionwithkey  "0200000001cfe62b9f1c52bc2998f9a0e6d6ee35430c93ec653d5691935178147a43090fee0000000000ffffffff01f0afd320766191d4c5c088ac00000000" "[\"cSXHtKRXWnCLWhuie8WC13cKF3qdnKL8vG3BiRpxgCXZkK2CHe9u\"]"  "[{\"txid\":\"ee0f09437a1478519391563d65ec930c4335eed6e6a0f99829bc521c9f2be6cf\",\"vout\":0,\"scriptPubKey\":\"a914111111111111111111111111111111111111111187\",\"redeemScript\":\"5221033d9aecbced8e776c03d283f6c0d64c6a301ad142d74d500fe8860c9b362fa4932102a4df3cb4e5286e180b7c68e323c778e32350a604d4f4a74c290d1c60c721687a52ae\"}]"

Looking further, I need to base58 encode the key.

  • signrawtransactionwithkey is for when you want to sign a raw transaction with a key you have that is not in your wallet. In that tutorial the key is just a key in your wallet, so you can avoid the issue of exporting the key by using signrawtransactionwithwallet instead. – Pieter Wuille Oct 28 '19 at 15:31

If you just want to sign the raw transaction as it's shown in the tutorial, please use signrawtransactionwithwallet instead. It would be like below.

$ signedtx2=$(bitcoin-cli -named signrawtransactionwithwallet hexstring=$rawtxhex2 | jq -r '.hex')
$ bitcoin-cli -named sendrawtransaction hexstring=$signedtx2
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.