15

I want to add some additional information to my specific transaction, so that I can send the additional information to blockchain.

2
  • possible duplicate of How to send bitcoin with a message attached
    – knaperek
    Oct 15, 2014 at 8:37
  • 1
    I don't think this is a duplicate, this question relates to adding the extra info into the block chain, the other is just trying to make an associated message with a transaction, such as in a "bitcoin:" URI.
    – morsecoder
    Oct 15, 2014 at 15:22

1 Answer 1

12

Note that you should only do this, putting extra data into the block chain, if it is really necessary. The block chain has to be stored by every full node, so try not to take up all our hard drive space with unnecessary stuff whenever possible.

With that said, if you do want to add extra data to your transaction, then add an additional output to the transaction, for which the scriptPubKey has the following form:

OP_RETURN {80 bytes of whatever data you want}

This transaction output is automatically un-spendable, and so will not be kept in the UTXO set. The other UTXOs from your transaction will still be safe.

For more info:

This will embed extra information into your transaction. Be aware, though, that the software that made the transaction and the software that reads the transaction have to be compatible in order for the user to be able to read the given information when the transaction is received.

You can see an example of a transaction that used OP_RETURN to encode extra information here: https://blockchain.info/tx/6dfb16dd580698242bcfd8e433d557ed8c642272a368894de27292a8844a4e75?show_adv=true.

9
  • 2
    Note that receivers (other outputs of your tx), or people in general, won't automatically see this information. People would have to know about your particular tx and specifically decode it and view its raw contents, in order to be aware of your info.
    – RocketNuts
    Oct 15, 2014 at 14:39
  • 1
    Where are you getting stuck? Can you tell me what you've tried?
    – morsecoder
    Oct 16, 2014 at 12:34
  • 2
    You're doing it wrong, look again at the example transaction linked in the answer, the third output is the OP_RETURN and the entire output script is "OP_RETURN 68656c6c6f20776f726c64" (decoded: jhello world). There is no OP_DUP, OP_HASH160, keyID, OP_EQUALVERIFY or OP_CHECKSIG in an OP_RETURN output script. It's an unspendable output that contains the OP_RETURN opcode and up to 40 bytes of arbitrary data, nothing more or less, it's a separate output from any pay to pubkey hash or pay to script hash outputs in the same transaction.
    – stevenh512
    Nov 9, 2014 at 19:00
  • 3
    I think the size changed in 2015 from 40 to 80. Right?
    – Leandro
    Apr 23, 2017 at 15:26
  • 1
    @Leandro Yes the size changed to 80 bytes Jul 10, 2018 at 11:25

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