<p>You can't just give Bitcoin Core the redeemScript, it won't know what to do with it. The only valid thing to give it is an address, but you have not given it an address. You need to convert your redeemScript into a P2SH address first, then you give it that address.</p>

<p>You can use the <code>decodescript</code> command to get both the p2sh and p2wsh addresses for your redeemScript:</p>

<pre><code>$ bitcoin-cli decodescript 63a820a967bf5e8ca09e059d6bb7a3efa8f62190284649d3eab773518827164ac481fb8876a914f5fb6147ff889a392211d0f0831a71137bedbff167064f505f323030064f505f4353567576a914cac5d03956494ffc17f78ea7b71189abf7f3593d6888ac
{
  "asm": "OP_IF OP_SHA256 a967bf5e8ca09e059d6bb7a3efa8f62190284649d3eab773518827164ac481fb OP_EQUALVERIFY OP_DUP OP_HASH160 f5fb6147ff889a392211d0f0831a71137bedbff1 OP_ELSE 4f505f323030 4f505f435356 OP_DROP OP_DUP OP_HASH160 cac5d03956494ffc17f78ea7b71189abf7f3593d OP_ENDIF OP_EQUALVERIFY OP_CHECKSIG",
  "type": "nonstandard",
  "p2sh": "33bzAemHYJdN1XciQGqj4v48F5YFinQGcY",
  "segwit": {
    "asm": "0 6b2b3b1c6a0f8c15b5cdac185339555ec0d537304b367f73ab615d55c9719607",
    "hex": "00206b2b3b1c6a0f8c15b5cdac185339555ec0d537304b367f73ab615d55c9719607",
    "reqSigs": 1,
    "type": "witness_v0_scripthash",
    "addresses": [
      "bc1qdv4nk8r2p7xptdwd4sv9xw24tmqd2desfvm87uatv9w4tjt3jcrs2a06tv"
    ],
    "p2sh-segwit": "3Erd7hDtmrGxvyEjcaqsARh8wfBfM9m4N5"
  }
}
</code></pre>

<p>As you can see, you can use the address <code>33bzAemHYJdN1XciQGqj4v48F5YFinQGcY</code> in your transaction. If you would like to use segwit, you can use <code>bc1qdv4nk8r2p7xptdwd4sv9xw24tmqd2desfvm87uatv9w4tjt3jcrs2a06tv</code>.</p>

CC BY-SA 4.0
2019-06-28T09:46:46.013Z
Thanks @Andrew. I have another question. Please guide me. After I fund the p2sh address. when i create a raw tx to redeem the fund of p2sh, i could not send to network directly. Since it needs to be signed.But how will get a private key of the p2sh address? Because when i did dumpprivkey for the p2sh , it was throwing an error "Address does not refer to a key".
kitty
CC BY-SA 4.0
2019-06-28T15:10:10.807Z
For this particular script, Bitcoin Core does not know how to sign for it, so you can't use Bitcoin Core to create the spending transaction. Furthermore, Bitcoin Core doesn't know the public key for this script, nor does it even know about this script unless you imported it. While it may have the private key for a public key in this script, because this script is not one of the standard patterns that it recognizes.
Ava Chow
CC BY-SA 4.0
2019-07-05T07:28:00.360Z
Thanks @Andrew . Could you please tell me any other ways how to proceed the above one?
kitty
CC BY-SA 4.0
2019-07-05T14:30:23.153Z
You will need to write some code that can make the signature and construct the final transaction. Bitcoin Core doesn't know how to sign or make the final transaction for this script, so you need to be able to do it yourself.
Ava Chow
CC BY-SA 4.0
2019-07-08T07:58:26.047Z
Thanks @Andrew . Even if i code myself , to sign such transaction how will i get private key ?
kitty
CC BY-SA 4.0
2019-07-08T14:33:15.950Z
You need to figure out what public keys are involved in your script. You can then get the legacy address for them (begins with a `1`) and export the private keys for those by using Bitcoin Core's `dumpprivkey` command.
Ava Chow
CC BY-SA 4.0
2019-07-09T06:40:37.483Z
Ok. But if I have a simple script (not involving any keys only contains hash ), in that case case how the signing take place?
kitty
CC BY-SA 4.0
2019-07-09T14:41:17.173Z
Then there are no private keys. You will still need to provide the inputs to the script so that it passes validation. There is no signing in such a script, just pushing the correct items to the stack.
Ava Chow
CC BY-SA 4.0
2019-06-26T14:35:57.127Z
2019-06-26T14:35:57.127Z
Ava Chow
<p>I am running bitcoin in regtest mode with 2 nodes bitcoinNode1 and bitcoinNode2.I have created a redeem script by writing the opcodes and converted into hex form using btcc.</p>

<pre><code>HP-ProBook-440-G4:~$ btcc OP_IF OP_SHA256 a967bf5e8ca09e059d6bb7a3efa8f62190284649d3eab773518827164ac481fb OP_EQUALVERIFY OP_DUP OP_HASH160 f5fb6147ff889a392211d0f0831a71137bedbff1 OP_ELSE OP_200 OP_CSV OP_DROP OP_DUP OP_HASH160 cac5d03956494ffc17f78ea7b71189abf7f3593d OP_ENDIF OP_EQUALVERIFY OP_CHECKSIG

O/p: 63a820a967bf5e8ca09e059d6bb7a3efa8f62190284649d3eab773518827164ac481fb8876a914f5fb6147ff889a392211d0f0831a71137bedbff167064f505f323030064f505f4353567576a914cac5d03956494ffc17f78ea7b71189abf7f3593d6888ac
</code></pre>

<p>Now i am trying to create a raw transaction using the redeem script.</p>

<pre><code>HP-ProBook-440-G4:~$ bitcoin-cli -regtest -datadir=./bitcoinNode1 -conf=./bitcoinNode1/bitcoin.conf -rpcuser=user1 -rpcport=19001 createrawtransaction "[{\"txid\":\"818978d31bf63158612d080c4a934a78a52f52f7bc797cc1f84f6ca8cc4b2dea\",\"vout\":0}]" "[{\"63a820a967bf5e8ca09e059d6bb7a3efa8f62190284649d3eab773518827164ac481fb8876a914f5fb6147ff889a392211d0f0831a71137bedbff167064f505f323030064f505f4353567576a914cac5d03956494ffc17f78ea7b71189abf7f3593d6888ac\":0.01}]"
</code></pre>

<p>But i am not able to create as it says invalid bitcoin address.</p>

<p>Should i convert the redeem script into p2sh? If yes can you please suggest how to create p2sh and do raw transaction with that p2sh?</p>

<bitcoind><script><raw-transaction>
Bitcoin raw transaction with manually created redeem script
kitty
# Bitcoin raw transaction with manually created redeem script

(Asked by: username_0 on 2019-06-26)

I am running bitcoin in regtest mode with 2 nodes bitcoinNode1 and bitcoinNode2.I have created a redeem script by writing the opcodes and converted into hex form using btcc.

```
HP-ProBook-440-G4:~$ btcc OP_IF OP_SHA256 a967bf5e8ca09e059d6bb7a3efa8f62190284649d3eab773518827164ac481fb OP_EQUALVERIFY OP_DUP OP_HASH160 f5fb6147ff889a392211d0f0831a71137bedbff1 OP_ELSE OP_200 OP_CSV OP_DROP OP_DUP OP_HASH160 cac5d03956494ffc17f78ea7b71189abf7f3593d OP_ENDIF OP_EQUALVERIFY OP_CHECKSIG

O/p: 63a820a967bf5e8ca09e059d6bb7a3efa8f62190284649d3eab773518827164ac481fb8876a914f5fb6147ff889a392211d0f0831a71137bedbff167064f505f323030064f505f4353567576a914cac5d03956494ffc17f78ea7b71189abf7f3593d6888ac

```

Now i am trying to create a raw transaction using the redeem script.

```
HP-ProBook-440-G4:~$ bitcoin-cli -regtest -datadir=./bitcoinNode1 -conf=./bitcoinNode1/bitcoin.conf -rpcuser=user1 -rpcport=19001 createrawtransaction "[{\"txid\":\"818978d31bf63158612d080c4a934a78a52f52f7bc797cc1f84f6ca8cc4b2dea\",\"vout\":0}]" "[{\"63a820a967bf5e8ca09e059d6bb7a3efa8f62190284649d3eab773518827164ac481fb8876a914f5fb6147ff889a392211d0f0831a71137bedbff167064f505f323030064f505f4353567576a914cac5d03956494ffc17f78ea7b71189abf7f3593d6888ac\":0.01}]"

```

But i am not able to create as it says invalid bitcoin address.

Should i convert the redeem script into p2sh? If yes can you please suggest how to create p2sh and do raw transaction with that p2sh?

**Tags:** bitcoind, script, raw-transaction


---

## 1 answers

### Answer by username_1 on 2019-06-26. Score: 2

You can't just give Bitcoin Core the redeemScript, it won't know what to do with it. The only valid thing to give it is an address, but you have not given it an address. You need to convert your redeemScript into a P2SH address first, then you give it that address.

You can use the `decodescript` command to get both the p2sh and p2wsh addresses for your redeemScript:

```
$ bitcoin-cli decodescript 63a820a967bf5e8ca09e059d6bb7a3efa8f62190284649d3eab773518827164ac481fb8876a914f5fb6147ff889a392211d0f0831a71137bedbff167064f505f323030064f505f4353567576a914cac5d03956494ffc17f78ea7b71189abf7f3593d6888ac
{
  "asm": "OP_IF OP_SHA256 a967bf5e8ca09e059d6bb7a3efa8f62190284649d3eab773518827164ac481fb OP_EQUALVERIFY OP_DUP OP_HASH160 f5fb6147ff889a392211d0f0831a71137bedbff1 OP_ELSE 4f505f323030 4f505f435356 OP_DROP OP_DUP OP_HASH160 cac5d03956494ffc17f78ea7b71189abf7f3593d OP_ENDIF OP_EQUALVERIFY OP_CHECKSIG",
  "type": "nonstandard",
  "p2sh": "33bzAemHYJdN1XciQGqj4v48F5YFinQGcY",
  "segwit": {
    "asm": "0 6b2b3b1c6a0f8c15b5cdac185339555ec0d537304b367f73ab615d55c9719607",
    "hex": "00206b2b3b1c6a0f8c15b5cdac185339555ec0d537304b367f73ab615d55c9719607",
    "reqSigs": 1,
    "type": "witness_v0_scripthash",
    "addresses": [
      "bc1qdv4nk8r2p7xptdwd4sv9xw24tmqd2desfvm87uatv9w4tjt3jcrs2a06tv"
    ],
    "p2sh-segwit": "3Erd7hDtmrGxvyEjcaqsARh8wfBfM9m4N5"
  }
}

```

As you can see, you can use the address `33bzAemHYJdN1XciQGqj4v48F5YFinQGcY` in your transaction. If you would like to use segwit, you can use `bc1qdv4nk8r2p7xptdwd4sv9xw24tmqd2desfvm87uatv9w4tjt3jcrs2a06tv`.

> **Comments:**
> **username_0**: Thanks @Andrew. I have another question. Please guide me. After I fund the p2sh address. when i create a raw tx to redeem the fund of p2sh, i could not send to network directly. Since it needs to be signed.But how will get a private key of the p2sh address? Because when i did dumpprivkey for the p2sh , it was throwing an error "Address does not refer to a key".  
> **username_1**: For this particular script, Bitcoin Core does not know how to sign for it, so you can't use Bitcoin Core to create the spending transaction. Furthermore, Bitcoin Core doesn't know the public key for this script, nor does it even know about this script unless you imported it. While it may have the private key for a public key in this script, because this script is not one of the standard patterns that it recognizes.  
> **username_0**: Thanks @Andrew . Could you please tell me any other ways how to proceed the above one?  
> **username_1**: You will need to write some code that can make the signature and construct the final transaction. Bitcoin Core doesn't know how to sign or make the final transaction for this script, so you need to be able to do it yourself.  
> **username_0**: Thanks @Andrew . Even if i code myself , to sign such transaction how will i get private key ?  
> **username_1**: You need to figure out what public keys are involved in your script. You can then get the legacy address for them (begins with a `1`) and export the private keys for those by using Bitcoin Core's `dumpprivkey` command.  
> **username_0**: Ok. But if I have a simple script (not involving any keys only contains hash ), in that case case how the signing take place?  
> **username_1**: Then there are no private keys. You will still need to provide the inputs to the script so that it passes validation. There is no signing in such a script, just pushing the correct items to the stack.  

---

