I want to add some additional information to my specific transaction, so that I can send the additional information to blockchain.
-
possible duplicate of How to send bitcoin with a message attached – knaperek Oct 15 '14 at 08:37
-
1I 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 '14 at 15:22
1 Answers
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:
- https://bitcointalk.org/index.php?topic=414886.0
- https://bitcoinfoundation.org/2013/10/core-development-update-5/
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.

- 29,396
- 11
- 72
- 130

- 14,168
- 2
- 42
- 94
-
2Note 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 '14 at 14:39
-
Thanks, @RocketNuts, I will edit my answer to include the information you gave. – morsecoder Oct 15 '14 at 15:17
-
Thank you very much for your reply. I'm sure this is the right way to do it, but I'm having some trouble with including data into the transaction object with OP_RETURN. I really appreciate you if you could help me with this. – Rasela Don Oct 16 '14 at 06:21
-
1
-
std::vector
data; *script << OP_DUP << OP_HASH160 << keyID << OP_EQUALVERIFY << OP_CHECKSIG << OP_RETURN << data; I just send the required data like this. I could successfully make the transaction, but it doesn't go to the block chain. I could find the type of the transaction as follows. "type": "nonstandard"
– Rasela Don Oct 17 '14 at 08:40 -
2You'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 09 '14 at 19:00
-
3
-
-
1