bitcoin-cli createrawtransaction and purpose of "scriptPubKey"?

1

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"?

pebwindkraft

Posted 2018-06-05T08:00:12.077

Reputation: 4 568

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

Adam 2018-06-05T09:25:34.373

Answers

2

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.

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

Raghav Sood

Posted 2018-06-05T08:00:12.077

Reputation: 10 897

1You 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.Adam 2018-06-05T08:52:26.573

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 2018-06-05T10:57:40.000

@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 2018-06-05T17:03:39.050

@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 2018-06-05T17:07:57.883

@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 2018-06-05T17:29:58.257

@ 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 2018-06-11T08:48:33.457