<p>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 <code>signrawtransactionwithkey</code>. Bitcoin core sign only the standard transaction</p>

CC BY-SA 4.0
2020-03-29T12:09:23.387Z
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
CC BY-SA 4.0
2020-03-29T12:30:31.717Z
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
CC BY-SA 4.0
2020-03-29T13:55:52.247Z
How can I create .pem private key file from bitcoin private key which I already had like e.g. **cSEpx7zcr9hbfah5FdHVHsVWN3CpJevtomgeJJaxgUvd9otzrYKV** with openssl ?
M A
CC BY-SA 4.0
2020-03-29T14:02:02.390Z
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
CC BY-SA 4.0
2020-03-29T15:55:00.067Z
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
CC BY-SA 4.0
2020-03-29T16:23:22.023Z
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
CC BY-SA 4.0
2020-03-29T16:44:08.117Z
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
CC BY-SA 4.0
2020-03-29T16:49:48.743Z
Maybe you need to open a new question with more details about signature
monkeyUser
CC BY-SA 4.0
2020-03-29T17:12:15.937Z
Okay, well, I appreciate it for your help anyway. Thank you :)
M A
CC BY-SA 4.0
2020-03-29T12:01:07.300Z
2020-03-29T12:01:07.300Z
monkeyUser
<p>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.</p>

CC BY-SA 4.0
2020-04-01T13:09:26.203Z
2020-04-01T13:09:26.203Z
M A
<p>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:</p>

<pre><code>asm: OP_HASH160 d0c3f50336b5f109207d722c692191ff86263e96 OP_EQUAL OP_DROP 1
hex: a914d0c3f50336b5f109207d722c692191ff86263e96877551
</code></pre>

<ol>
<li>I created raw transaction</li>
</ol>

<pre><code>createrawtransaction '[{"txid":"1c164f99a7cd0fe6dba9a7fe10ad3c2be132a9260d4ccdeaf7e279073946ac52","vout":0}]' '{"2MxmdfXx8rKGUmWUwQu59GksMNRdnQiRRM2":0.195}'

020000000152ac46390779e2f7eacd4c0d26a932e12b3cad10fea7a9dbe60fcda7994f161c0000000000ffffffff01e08b29010000000017a9143c98df42d7a69c7fd165aeb6128d45f21eeeac4d8700000000
</code></pre>

<ol start="2">
<li>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</li>
</ol>

<pre><code>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)

</code></pre>

<p>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:</p>

<ol>
<li><p>What am I doing wrong?</p></li>
<li><p>Can I create custom transactions using the Bitcoin core, if so how?</p></li>
<li><p>If I can't use this wallet, how can I do it? I would be grateful for an example</p></li>
</ol>

<bitcoin-core><transactions><testnet><raw-transaction><opcodes>
Creating a custom transactions
M A
# Creating a custom transactions

(Asked by: username_0 on 2020-03-29)

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

```

2. 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

**Tags:** bitcoin-core, transactions, testnet, raw-transaction, opcodes


---

## 2 answers

### Answer by username_1 on 2020-03-29. Score: 1 | Accepted answer

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

> **Comments:**
> **username_0**: 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?  
> **username_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  
> **username_0**: How can I create .pem private key file from bitcoin private key which I already had like e.g. **cSEpx7zcr9hbfah5FdHVHsVWN3CpJevtomgeJJaxgUvd9otzrYKV** with openssl ?  
> **username_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  
> **username_0**: 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.  
> **username_1**: 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.  
> **username_0**: 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.  
> **username_1**: Maybe you need to open a new question with more details about signature  
> **username_0**: Okay, well, I appreciate it for your help anyway. Thank you :)  

---

### Answer by username_0 on 2020-04-01. Score: 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.


---

