Title: [Q] How to add payload to bitcoin transactions? Post by: subezi on July 11, 2018, 05:41:38 AM Hi All,
Could anybody point me to a good tutorial? I would like to know how to add data (txt) to a bitcoin tx. I read somewhere that 80 byte would be doable but I don't know if this is correct. Any help is greatly appreciated. Thx & cheers, Subezi Title: Re: [Q] How to add payload to bitcoin transactions? Post by: starmyc on July 11, 2018, 08:25:44 AM You want to send a transaction with a null data output in it, as documented at https://bitcoin.org/en/developer-guide#null-data
Currently, the bitcoin protocol allows a length 83 bytes, including the mandatory OP_RETURN in it. AFAIK, you can't do that within the GUI (well, you can using the debug window), and you just have to use the use the createrawtransaction/signrawtransaction/sendrawtransaction to achieve that. First, make sure you have unspent UTXO to send your coins. I'll be using the testnet to make in my example: Code: $ alias btc-test="bitcoin-cli -testnet" Then, you create your new raw transaction, using this unspent output. In this transaction, I'll send the coins back to the same address (minus fees - 0.0005; I'm freaky generous on this one!), and send the "hello subezi"-md5sum hashed message: Code: $ echo "hello subezi" | md5sum You can check with "decoderawtransaction" the transaction back: Code: $ TX=020000000106710b44623c48d6b61f77d970e6751c81b562408bf879a1f8eb0112105770170000000000ffffffff024031f7000000000017a914ba41857257b590385a85a1d52ac8661d998fb048870000000000000000126a1066901913e0cdea467afd40ef844823df00000000 Next step is to sign the transaction, using signrawtransaction: Code: $ btc-test signrawtransaction $TX And finally, last step, to send this signed transaction to the network: Code: $ export SIGNED=0200000000010106710b44623c48d6b61f77d970e6751c81b562408bf879a1f8eb0112105770170000000017160014b4fb6c09924a8345888378b44c5a267536b0da8effffffff024031f7000000000017a914ba41857257b590385a85a1d52ac8661d998fb048870000000000000000126a1066901913e0cdea467afd40ef844823df02483045022100c31561e63c0bc0f023dd05008b7c25e48079ae36bc6942b971eb49080ca605f502206cf6743c986b0d1e2507deb9147728e006a895a2b6bbe477bd61eacb54574305012103029926e88dabdcdc6e24702d4f4b6209438166d23200f604b3604cdfa1aa06ac00000000 And you can check that this transaction has stored in the blockchain your initial message, using any good block explorer, simply like this https://testnet.blockchain.info/tx/259fbbba743bb54a116b114b1faed137f9f005e478c80759d446c4f03e06824a?show_adv=true Code: $ curl -s https://testnet.blockchain.info/rawtx/259fbbba743bb54a116b114b1faed137f9f005e478c80759d446c4f03e06824a|grep 66901913e0cdea467afd40ef844823df Have fun sending custom data in the blockchain! Title: Re: [Q] How to add payload to bitcoin transactions? Post by: subezi on July 11, 2018, 10:51:58 AM hey thank you very much for this comprehensive answer! :D
|