Author

Topic: Specifying OP_RETURN when creating a raw transaction (Read 2450 times)

newbie
Activity: 29
Merit: 0
In python you could specify the OP_RETURN value as follows:

Code:
from binascii import unhexlify

msg = 'your message of max 40 chars'
# convert msg to OP_RETURN script in hexadecimal
hexed = "6a%x%s" % (len(msg), msg.encode('hex'))
# convert to binary encoding
script = unhexlify(hexed)
Set the value of the output to 0.0, replace the transaction script with the binary part above.

Do not forget to add enough fee and send the remainder to your change address.
newbie
Activity: 50
Merit: 0
I probably don't understand this as well as you do (obviously), so pardon some of the obviousness of my question.

I realize opcode 0x6a is what refers to OP_RETURN. I noticed this in the HEX for some of the TX's already on the blockchain that have OP_RETURN output scripts. It seems (if I get it right) that it is something like 0x6a

Not too sure what you meant when you said to put the opcode 0x6a in front of the script followed by the length prefix.

Since the bitcoind client does not let you specify output scripts (per my knowledge) when creating a raw transaction, I am going with the idea that I have to take the output of createrawtransaction, and modify it to additionally include OP_RETURN somehow.

What approach were you referring to?
legendary
Activity: 905
Merit: 1012
You have to do something custom to put data on the blockchain anyway. And using OP_RETURN is easy: put the opcode (0x6a) in the front of the script, and increment the length prefix.
newbie
Activity: 50
Merit: 0
My understanding is are being considered because people are resorting to creating unspendable UXTO's to "embed" data. This would pollute the blockchain and is not something that can be stopped, so since we can't stop it, let's at least provide a cleaner way to do it, albeit we would prefer it not be done at all.

Is this sort of the point and why this won't be a feature that will be easily provided?

Problem is, it is still way easier to do the former than it is to use OP_RETURN, from how I understand things, so unless you make it at least reasonably as easy/hard to use OP_RETURN as it is to do the former, it is sort of pointless.

But more generally, how do you even specify your own output scripts? What if you want to something fancier than just sending BTC to one or more recipients using the already-supported script operarations. How would you even do that? Is the reference bitcoin client not meant to support this?
staff
Activity: 4284
Merit: 8808
There isn't currently a direct facility for it— because it's not generally something you're supposed to use.

OP_RETURN is like giving out clean needles to heroin addicts.  It's there as harm mitigation, but it isn't something thats generally good for the system.

When there is an actual application for using them in the software then that will be exposed— but just using it to cram data into transactions and externalize your storage costs onto the network? No.
newbie
Activity: 50
Merit: 0
Is this something that can't be done yet (unless using a 0.9 release candidate)?

I know that people have already sent out TX's that specify OP_RETURN in the output scripts, but I can't seem to see how to do this. I apologize if I should have put this in a different forum -- not sure.

Thanks.
Jump to: