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

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.

  • 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. – Adam Jun 5 '18 at 8:52
  • 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 Jun 5 '18 at 10:57
  • @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 Jun 5 '18 at 17:03
  • @PieterWuille Looks like it was mentioned in some issues/examples years ago, and a bunch of tutorials now just copy that: github.com/bitcoin/bitcoin/issues/6483, bitcoin.stackexchange.com/q/35750/7272 – Raghav Sood Jun 5 '18 at 17:07
  • @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 Jun 5 '18 at 17:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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