<p>Currently, the create raw transaction method only uses the <code>txid</code> and <code>vout</code> parameters from that argument. You can view the relevant part of the source <a href="https://github.com/bitcoin/bitcoin/blob/master/src/rpc/rawtransaction.cpp#L384" rel="nofollow noreferrer">here</a>.</p>
<p>For all practical purposes, you could pass in <code>00</code> for the scriptPubKey and still get the same result.</p>

CC BY-SA 4.0
2018-06-05T08:52:26.573Z
You are right, I've been working with all addresses types and I've never attached it. so yes, it's totally not required. you don't even have to pass anything.
Tailer
CC BY-SA 4.0
2018-06-05T10:57:40.000Z
Yup, this was also my assumption, based on my tests (and perception). It’s just that I am not good enough in understanding the sources - and I am not comfortable with the „code is documentation“ approach... thx for confirmation!
pebwindkraft
CC BY-SA 4.0
2018-06-05T17:03:39.050Z
@pebwindcraft Where did you even read about passing a scriptPubKey argument there? As far as I can see this is not mentioned anywhere; not in the code, not in the RPC help, and not on the developer documentation on bitcoin.org. There simply is no such field, expected or used in any way.
Pieter Wuille
CC BY-SA 4.0
2018-06-05T17:07:57.883Z
@PieterWuille Looks like it was mentioned in some issues/examples years ago, and a bunch of tutorials now just copy that: https://github.com/bitcoin/bitcoin/issues/6483, https://bitcoin.stackexchange.com/q/35750/7272
Raghav Sood
CC BY-SA 4.0
2018-06-05T17:29:58.257Z
@RaghavSood Ah, I see. I think it's just `signrawtransaction` that need `scriptPubKey` (when the UTXO is not known to wallet or node), and people simplify things and pass the same argument to `createrawtransaction` as well - but it has never had any use there.
Pieter Wuille
CC BY-SA 4.0
2018-06-11T08:48:33.457Z
@ PieterWuille (and all): indeed, also with the current daemon (v0.16.0) "bitcoin-cli -help createrawtransaction" there is nothing mentioned with "scriptPubKey" in the documentation. I surely used "older" posts. I thought I'd get an error when providing a wrong parameter, just to find out that the above example returns no error. I also tried to provide "scripPubKey_xyz" or "scriptPubKey_abc", or several other parameters. "bitcoin-cli createrawtransaction" would not through an error on these wrong or useless keyword parameters.
pebwindkraft
CC BY-SA 4.0
2018-06-05T08:26:29.097Z
2018-06-05T08:26:29.097Z
2020-06-16T11:10:03.350Z
Raghav Sood
<p>I am playing with P2SH on regtest and try to understand the logic of creating and signing tx with bitcoin daemon. I am on version 0.15.1, and try to create a tx. </p>

<p>The used  scriptPubKey results from a simple if/else/endif statement, not from a standard multisig approach. So I manually created the redeem script, and turned it into an address (beginning with "2"). I then created a transaction, that funds this address. Now I want to spend these funds. While creating the transaction, I discovered that the usage of "scriptPubKey" does not change anything in my output. </p>

<p>Example without "scriptPubKey":</p>

<pre><code>bitcoin-cli -regtest createrawtransaction '''[{"txid":"'b5b67997f36627a461cd5ee1951aa775a68faa0c11c50b8f068ea1c7f4a9b087'","vout":'0'}]''' '''{"'mgpe9b44YYYbhDE1dbWosCSQDPYFkkoHjt'":'9.99995000'}''' 
020000000187b0a9f4c7a18e068f0bc5110caa8fa675a71a95e15ecd61a42766f39779b6b50000000000ffffffff0178b69a3b000000001976a9140e507731ec9a94d454424f3ca65917a2abb45f4988ac00000000
</code></pre>

<p>Example with "scriptPubKey":</p>

<pre><code>bitcoin-cli -regtest createrawtransaction '''[{"txid":"'b5b67997f36627a461cd5ee1951aa775a68faa0c11c50b8f068ea1c7f4a9b087'","vout":'0',"scriptPubKey":"'a914d53c738d730d8623eb2a070833599157beb3f6f687'"}]''' '''{"'mgpe9b44YYYbhDE1dbWosCSQDPYFkkoHjt'":'9.99995000'}'''
020000000187b0a9f4c7a18e068f0bc5110caa8fa675a71a95e15ecd61a42766f39779b6b50000000000ffffffff0178b69a3b000000001976a9140e507731ec9a94d454424f3ca65917a2abb45f4988ac00000000
</code></pre>

<p>The result is exactly the same. When the result is the same, what is the purpose of using this field as a parameter to "createrawtransaction"?</p>

CC BY-SA 4.0
2018-06-05T09:25:34.373Z
I don't see anywhere that scriptPubkey required when you create a raw transaction.
https://bitcoin.org/en/developer-reference#createrawtransaction
Tailer
<createrawtransaction>
bitcoin-cli createrawtransaction and purpose of "scriptPubKey"?
pebwindkraft
# bitcoin-cli createrawtransaction and purpose of "scriptPubKey"?

(Asked by: username_0 on 2018-06-05)

I am playing with P2SH on regtest and try to understand the logic of creating and signing tx with bitcoin daemon. I am on version 0.15.1, and try to create a tx. 
The used  scriptPubKey results from a simple if/else/endif statement, not from a standard multisig approach. So I manually created the redeem script, and turned it into an address (beginning with "2"). I then created a transaction, that funds this address. Now I want to spend these funds. While creating the transaction, I discovered that the usage of "scriptPubKey" does not change anything in my output. 
Example without "scriptPubKey":
bitcoin-cli -regtest createrawtransaction '''[{"txid":"'b5b67997f36627a461cd5ee1951aa775a68faa0c11c50b8f068ea1c7f4a9b087'","vout":'0'}]''' '''{"'mgpe9b44YYYbhDE1dbWosCSQDPYFkkoHjt'":'9.99995000'}''' 
020000000187b0a9f4c7a18e068f0bc5110caa8fa675a71a95e15ecd61a42766f39779b6b50000000000ffffffff0178b69a3b000000001976a9140e507731ec9a94d454424f3ca65917a2abb45f4988ac00000000

Example with "scriptPubKey":
bitcoin-cli -regtest createrawtransaction '''[{"txid":"'b5b67997f36627a461cd5ee1951aa775a68faa0c11c50b8f068ea1c7f4a9b087'","vout":'0',"scriptPubKey":"'a914d53c738d730d8623eb2a070833599157beb3f6f687'"}]''' '''{"'mgpe9b44YYYbhDE1dbWosCSQDPYFkkoHjt'":'9.99995000'}'''
020000000187b0a9f4c7a18e068f0bc5110caa8fa675a71a95e15ecd61a42766f39779b6b50000000000ffffffff0178b69a3b000000001976a9140e507731ec9a94d454424f3ca65917a2abb45f4988ac00000000

The result is exactly the same. When the result is the same, what is the purpose of using this field as a parameter to "createrawtransaction"?

**Tags:** createrawtransaction

> **Comments:**
> **username_1**: I don't see anywhere that scriptPubkey required when you create a raw transaction. https://bitcoin.org/en/developer-reference#createrawtransaction  

---

## 1 answers

### Answer by username_2 on 2018-06-05. Score: 3 | Accepted answer

Currently, the create raw transaction method only uses the `txid` and `vout` parameters from that argument. You can view the relevant part of the source [here](https://github.com/bitcoin/bitcoin/blob/master/src/rpc/rawtransaction.cpp#L384).

For all practical purposes, you could pass in `00` for the scriptPubKey and still get the same result.

> **Comments:**
> **username_1**: You are right, I've been working with all addresses types and I've never attached it. so yes, it's totally not required. you don't even have to pass anything.  
> **username_0**: Yup, this was also my assumption, based on my tests (and perception). It’s just that I am not good enough in understanding the sources - and I am not comfortable with the „code is documentation“ approach... thx for confirmation!  
> **username_3**: @pebwindcraft Where did you even read about passing a scriptPubKey argument there? As far as I can see this is not mentioned anywhere; not in the code, not in the RPC help, and not on the developer documentation on bitcoin.org. There simply is no such field, expected or used in any way.  
> **username_2**: @PieterWuille Looks like it was mentioned in some issues/examples years ago, and a bunch of tutorials now just copy that: https://github.com/bitcoin/bitcoin/issues/6483, https://bitcoin.stackexchange.com/q/35750/7272  
> **username_3**: @RaghavSood Ah, I see. I think it's just `signrawtransaction` that need `scriptPubKey` (when the UTXO is not known to wallet or node), and people simplify things and pass the same argument to `createrawtransaction` as well - but it has never had any use there.  
> **username_0**: @ PieterWuille (and all): indeed, also with the current daemon (v0.16.0) "bitcoin-cli -help createrawtransaction" there is nothing mentioned with "scriptPubKey" in the documentation. I surely used "older" posts. I thought I'd get an error when providing a wrong parameter, just to find out that the above example returns no error. I also tried to provide "scripPubKey_xyz" or "scriptPubKey_abc", or several other parameters. "bitcoin-cli createrawtransaction" would not through an error on these wrong or useless keyword parameters.  

---

