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

<pre><code>$ signedtx2=$(bitcoin-cli -named signrawtransactionwithwallet hexstring=$rawtxhex2 | jq -r '.hex')
$ bitcoin-cli -named sendrawtransaction hexstring=$signedtx2
69c9ef4d1adb48596c470146ee9b60593023b6eb870b79ef666a8c9369768469
</code></pre>

CC BY-SA 4.0
2019-11-07T14:47:59.553Z
2019-11-07T14:47:59.553Z
ogw_yuya
<p>I am following <a href="https://github.com/ChristopherA/Learning-Bitcoin-from-the-Command-Line/blob/master/04_4_Sending_Coins_with_a_Raw_Transaction.md" rel="nofollow noreferrer">this tutorial</a>, which says to use <code>signrawtransaction</code>. However, I get:</p>

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

<p>The API call in the tutorial shows this:</p>

<pre><code>$ signedtx2=$(bitcoin-cli -named signrawtransaction hexstring=$rawtxhex2 | jq -r '.hex')
</code></pre>

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

<p><a href="https://gist.github.com/rietta/3640002" rel="nofollow noreferrer">https://gist.github.com/rietta/3640002</a></p>

<p>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.</p>

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

<p>Looking further, I need to <a href="https://bitcoin.stackexchange.com/questions/8247/how-can-i-convert-a-sha256-hash-into-a-bitcoin-base58-private-key">base58 encode the key</a>.</p>

CC BY-SA 4.0
2019-10-28T15:31:48.707Z
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
<transactions><private-key>
How to start using signrawtransactionwithkey instead of signrawtransaction
Lance Pollard
# How to start using signrawtransactionwithkey instead of signrawtransaction

(Asked by: username_0 on 2019-10-28)

I am following [this tutorial](https://github.com/ChristopherA/Learning-Bitcoin-from-the-Command-Line/blob/master/04_4_Sending_Coins_with_a_Raw_Transaction.md), 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:

<https://gist.github.com/rietta/3640002>

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](https://bitcoin.stackexchange.com/questions/8247/how-can-i-convert-a-sha256-hash-into-a-bitcoin-base58-private-key).

**Tags:** transactions, private-key

> **Comments:**
> **username_1**: 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.  

---

## 1 answers

### Answer by username_2 on 2019-11-07. Score: 1

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
69c9ef4d1adb48596c470146ee9b60593023b6eb870b79ef666a8c9369768469

```


---

