1

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

2 Answers 2

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

9
  • 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
    Commented Mar 29, 2020 at 12:09
  • 1
    check this link bitcoin.stackexchange.com/questions/93342/… Then depends on which program you use, I tried with openssl
    – monkeyUser
    Commented Mar 29, 2020 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
    Commented Mar 29, 2020 at 13:55
  • 1
    that WIF private key, you need decode base58 and remove prefix and compression byte. Check even this link man bitcointalk.org/index.php?topic=5226185.0 and bitcointalk.org/index.php?topic=5230931.0
    – monkeyUser
    Commented Mar 29, 2020 at 14:02
  • 1
    Okay, well, I appreciate it for your help anyway. Thank you :)
    – M A
    Commented Mar 29, 2020 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.

Your Answer

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

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