Does createrawtransaction have the ability to create a transaction with custom scripts?

5

4

Does createrawtransaction always use the following script?

scriptPubKey: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
scriptSig: <sig> <pubKey>

If so, how do you create a transaction that uses a custom scriptPubKey value? If not, what is the syntax for writing the JSON that enables custom scriptPubKey values for the transaction using createrawtransaction?

bvpx

Posted 2013-10-21T15:43:05.880

Reputation: 1 052

Answers

1

Yes that is correct.

What you can do is:

  • listunspent
  • createrawtransaction with receiver:amount and your change:amount
    • (make the amount differ to pay the fee)

Take the raw hex transaction and use it with http://brainwallet.org/#tx to be able to edit in JSON format. Don't worry, when your done you can sign the raw transaction in your local client.

About scriptPubKey, that is a little harder, and you should only experiment with this on testnet. You can try to understand this transaction https://en.bitcoin.it/wiki/Script#Transaction_puzzle and also try to understand how the stack works by playing around with jsforth

Jonas Oestman

Posted 2013-10-21T15:43:05.880

Reputation: 474

I have a good idea of how the stack works, and I don't want to use an external site to create my transactions. I'm assuming brainwallet is open source and I can view how they modify the scriptPubKey there? There is no way to simply write {address:amount,scriptPubKey:stuffhere} in the second field of createrawtransaction?bvpx 2013-10-21T17:51:57.377

Also, what does "Yes, that's correct" refer to?bvpx 2013-10-21T17:54:31.877

about createrawtransaction, yes that's correct, it only uses the basic script. about trusting an external site... you dont, its only for convenience... you should always check with decoderawtransaction that it will do what you really wantJonas Oestman 2013-10-21T18:02:20.060

It's not about trust, I want to learn how to do it myself, I guess at this point the best way is to read the sourcecode of brainwallet and understand how they are doing it. Unless there is documentation somewhere outlining the process.bvpx 2013-10-21T18:47:45.570

brainwallet is only one implementation of how to make a raw transaction, here you can learn about the raw hex and what every bit means https://en.bitcoin.it/wiki/Protocol_specification#tx

Jonas Oestman 2013-10-21T20:23:58.610

Okay, so I would construct a raw transaction using that specification, then sign it and send it with bitcoind after I am sure the data is correct using decoderawtransaction?bvpx 2013-10-21T20:32:45.823

Yes that is exactly right! You can check an already signed transaction with signrawtransaction with empty arguments like so [] [], and if all is good it will respond with the same raw transaction and complete:trueJonas Oestman 2013-10-21T21:37:19.577

I'm a bit confused about the transaction header. I've dug up some raw transactions I've signed previously with createrawtransaction then signrawtransaction, I am finding that the first 4 bytes are always the same (as expected). However the next 12 bytes that represent the "tx command" are different. How is that possible? Also, what exactly is the 4 byte payload checksum, and how is it derived?bvpx 2013-10-21T21:50:39.420

The transaction starts with 01 00 00 00, so you dont need to care about how the transaction is broadcasted and how the payload checksum is calculated or why

Jonas Oestman 2013-10-21T22:26:33.560

Sorry to keep this thread going, but... what do you mean "I don't need to care"? If I'm writing this entire transaction by hand, how do I know what to write for those bits? You're saying I can write anything there and it will be fine? It's extremely frustrating to try to learn this protocol because the documentation is very poor.bvpx 2013-10-21T22:30:57.963

Are you going to create software that can broadcast your transaction to the bitcoin network? If you are, go to the github repository. If you will use sendrawtransaction from bitcoin-qt or bitcoind, then you do not need to use the Message header.

Jonas Oestman 2013-10-22T00:44:02.537

Something is very unclear to me: if I can't use createrawtransaction to write a transaction with a custom script, how do I build the raw transaction that I eventually sign and broadcast with sendrawtransaction?bvpx 2013-10-22T04:46:48.883

Your script need to collect "prev_outputs" that you know you can sign later. Then create a JSON transaction. Convert that JSON to a raw hex transaction and sign it with signrawtransaction (or you can write your own code). I found how you can send it with python

Jonas Oestman 2013-10-22T05:51:33.913

I mean, I know how to create a standard raw transaction with createrawtransaction, sign it and broadcast it. My question refers to adding custom OPcodes to the scriptPubKey, if I can't do that with createrawtransaction then how is it done? I want to create this transaction however possible then send it with regular bitcoind.bvpx 2013-10-22T06:00:51.320

createrawtransaction is only a first step, to be able to play around with transactions. I don't think they will ever add the ability to do custom OPcodes. I want the same thing, make transactions by code, but I dont know how. Ask at bitcointalkJonas Oestman 2013-10-22T06:11:01.430