1

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?

1 Answer 1

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.

8
  • 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
    Jun 28, 2019 at 9:46
  • 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.
    – Andrew Chow
    Jun 28, 2019 at 15:10
  • Thanks @Andrew . Could you please tell me any other ways how to proceed the above one?
    – kitty
    Jul 5, 2019 at 7:28
  • 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.
    – Andrew Chow
    Jul 5, 2019 at 14:30
  • Thanks @Andrew . Even if i code myself , to sign such transaction how will i get private key ?
    – kitty
    Jul 8, 2019 at 7:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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