0

I am currently learning how to create raw transactions. I can already create standard using bitcoin core (0.19.1), but when I wanted to create with custom opcode like this:

asm: OP_HASH160 d0c3f50336b5f109207d722c692191ff86263e96 OP_EQUAL OP_DROP 1
hex: a914d0c3f50336b5f109207d722c692191ff86263e96877551
  1. I created raw transaction
createrawtransaction '[{"txid":"1c164f99a7cd0fe6dba9a7fe10ad3c2be132a9260d4ccdeaf7e279073946ac52","vout":0}]' '{"2MxmdfXx8rKGUmWUwQu59GksMNRdnQiRRM2":0.195}'

020000000152ac46390779e2f7eacd4c0d26a932e12b3cad10fea7a9dbe60fcda7994f161c0000000000ffffffff01e08b29010000000017a9143c98df42d7a69c7fd165aeb6128d45f21eeeac4d8700000000
  1. But when I wanted to sign this transaction I occured an error (I also tried to modify raw transaction from first step) here is result with modified raw transaction from above but it still doesn't work
signrawtransactionwithkey '020000000152ac46390779e2f7eacd4c0d26a932e12b3cad10fea7a9dbe60fcda7994f161c0000000000ffffffff0130c11d000000000019a914d0c3f50336b5f109207d722c692191ff86263e9687755100000000' '["$privkey"]' '[{"txid":"1c164f99a7cd0fe6dba9a7fe10ad3c2be132a9260d4ccdeaf7e279073946ac52","vout":0,"scriptPubKey":"a914d0c3f50336b5f109207d722c692191ff86263e96877551","redeemScript":"001453352afbbaa8cad22304201de8fbcc29e83fb2db","amount":0.02}]'

Previous output scriptPubKey mismatch:
OP_HASH160 d0c3f50336b5f109207d722c692191ff86263e96 OP_EQUAL
vs:
OP_HASH160 d0c3f50336b5f109207d722c692191ff86263e96 OP_EQUAL OP_DROP 1 (code -22)

Now I know I'm doing something wrong, but I don't know what and I can't find any information on how to do it correctly. That's why I have questions:

  1. What am I doing wrong?

  2. Can I create custom transactions using the Bitcoin core, if so how?

  3. If I can't use this wallet, how can I do it? I would be grateful for an example

M A
  • 79
  • 1
  • 7

2 Answers2

1

In your script the previous ScriptPubKey is different. If you want create custom script you need to sign manually the transaction, you can't use signrawtransactionwithkey. Bitcoin core sign only the standard transaction

monkeyUser
  • 960
  • 1
  • 7
  • 18
  • I know that ScriptPubKey is different, I mention that i modified him with hope that it will change something. How can I manually sign the transaction, can You give me some example? – M A Mar 29 '20 at 12:09
  • 1
    check this link https://bitcoin.stackexchange.com/questions/93342/sign-transaction-legacy-with-openssl Then depends on which program you use, I tried with openssl – monkeyUser Mar 29 '20 at 12:30
  • How can I create .pem private key file from bitcoin private key which I already had like e.g. **cSEpx7zcr9hbfah5FdHVHsVWN3CpJevtomgeJJaxgUvd9otzrYKV** with openssl ? – M A Mar 29 '20 at 13:55
  • 1
    that WIF private key, you need decode base58 and remove prefix and compression byte. Check even this link man https://bitcointalk.org/index.php?topic=5226185.0 and https://bitcointalk.org/index.php?topic=5230931.0 – monkeyUser Mar 29 '20 at 14:02
  • I tried to understand what you sent, but it's harder than I thought and well ... I don't understand. Too many unknowns and few explanations, could you explain such signing step by step? I know I am asking you a lot but I really care about it and I would like to understand it. – M A Mar 29 '20 at 15:55
  • In the second link you can find step by step from WIF to Pem. Or If you want, you can generate address from scratch by bash or some library. In that way you have all keys. Then Decide what kind of library use to sign transaction manually. – monkeyUser Mar 29 '20 at 16:23
  • Yes, I did it, but unfortunately it just doesn't work. The number of steps is simply too large to find an error somewhere. I have a problem that I don't know how to sign manually, even using the links you gave here. – M A Mar 29 '20 at 16:44
  • Maybe you need to open a new question with more details about signature – monkeyUser Mar 29 '20 at 16:49
  • 1
    Okay, well, I appreciate it for your help anyway. Thank you :) – M A Mar 29 '20 at 17:12
0

The problem was that I changed scriptPubKey, which I misinterpreted as scriptOutput of a future transaction. This was an error, scriptPubKey of the last parameter refers to scriptPubKey UTXO.

M A
  • 79
  • 1
  • 7