0
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?
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 – 2019-06-28T09:46:46.013
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 – 2019-06-28T15:10:10.807
Thanks @Andrew . Could you please tell me any other ways how to proceed the above one? – kitty – 2019-07-05T07:28:00.360
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 – 2019-07-05T14:30:23.153
Thanks @Andrew . Even if i code myself , to sign such transaction how will i get private key ? – kitty – 2019-07-08T07:58:26.047
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'sdumpprivkeycommand. – Andrew Chow – 2019-07-08T14:33:15.950Ok. But if I have a simple script (not involving any keys only contains hash ), in that case case how the signing take place? – kitty – 2019-07-09T06:40:37.483
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. – Andrew Chow – 2019-07-09T14:41:17.173
Ok. Thanks @andrew – kitty – 2019-07-15T08:37:05.210