Pages:
Author

Topic: [WTB] Teach me to manually create an OP_RETURN tx (Read 6245 times)

newbie
Activity: 4
Merit: 0
Here's a straightforward and simple guide how to do it

https://btcleak.com/2020/06/26/guide-push-any-data-on-to-the-blockchain-forever/

Yeah, I know I bumped a 4 year old thread Cheesy
legendary
Activity: 1106
Merit: 1026
I have a problem trying to decode the data back
Is there any way I can see the data I added while creating raw transaction without using this website?  --> https://live.blockcypher.com/btc/tx/b394e47f8141f725f25854d57e91fb67d91782dbe581b2f449990ba25a116d2d/

In Bitcoin Core, you can use:

Code:
bitcoin-cli getrawtransaction  1

However, the data then isn't shown isolated, but embedded in an output script. And since it's hex, you may also need to decode it.



By the way, thanks a lot for the one sending 0.0518131 BTC to my tip address posted in this thread! Smiley

https://live.blockcypher.com/btc/tx/d73a543383bcfe62fa86e8624f06a1fdcafd3a1018a9c3feb709318b1c60e7fd/
newbie
Activity: 1
Merit: 0
So instead of entering a receiving address and an amount one would enter '{"data":40_bytes}' ?

Yes, basically it comes down to this. Smiley

Here is an example:

1. First, I list unspent outputs of the address I'm going to use.

Code:
bitcoin-cli listunspent 0 999999 '["1BxtgEa8UcrMzVZaW32zVyJh4Sg4KGFzxA"]'


..........


5. Here is the result:

https://live.blockcypher.com/btc/tx/b394e47f8141f725f25854d57e91fb67d91782dbe581b2f449990ba25a116d2d/

Wink

I have a problem trying to decode the data back
Is there any way I can see the data I added while creating raw transaction without using this website?  --> https://live.blockcypher.com/btc/tx/b394e47f8141f725f25854d57e91fb67d91782dbe581b2f449990ba25a116d2d/
copper member
Activity: 3948
Merit: 2201
Verified awesomeness ✔
Is there anyway I can recreate this in the console of Electrum? It has a createrawtx function, but I can't find anything about it online.
legendary
Activity: 1106
Merit: 1026
So instead of entering a receiving address and an amount one would enter '{"data":40_bytes}' ?

Yes, basically it comes down to this. Smiley

Here is an example:

1. First, I list unspent outputs of the address I'm going to use.

Code:
bitcoin-cli listunspent 0 999999 '["1BxtgEa8UcrMzVZaW32zVyJh4Sg4KGFzxA"]'

Code:
[
  {
    "txid": "7425deeaebc2b13ff6c6d3cac78332693c86f46433403f65aef028bc88050583",
    "vout": 4,
    "address": "1BxtgEa8UcrMzVZaW32zVyJh4Sg4KGFzxA",
    "account": "Sender15",
    "scriptPubKey": "76a914784345e76ea29fd7bfe31f6f34622e154d0bb8fc88ac",
    "amount": 0.00110691,
    "confirmations": 558,
    "spendable": true
  }
]

2. Then I create the raw transaction. Note that I manually add a change output with a value of 0.00100691, so I pay a fee of exactly 0.0001 BTC. The payload for this transaction is the hex-encoded message "dexX7 @ bitcointalk.org".

Code:
bitcoin-cli createrawtransaction '[{"txid":"7425deeaebc2b13ff6c6d3cac78332693c86f46433403f65aef028bc88050583","vout":4}]' '{"data":"6465785837204020626974636f696e74616c6b2e6f7267","1BxtgEa8UcrMzVZaW32zVyJh4Sg4KGFzxA":0.00100691}'

Code:
010000000183050588bc28f0ae653f403364f4863c693283c7cad3c6f63fb1c2ebeade25740400000000ffffffff020000000000000000196a176465785837204020626974636f696e74616c6b2e6f726753890100000000001976a914784345e76ea29fd7bfe31f6f34622e154d0bb8fc88ac00000000

3. Then I sign the raw transaction.

Code:
bitcoin-cli signrawtransaction 010000000183050588bc28f0ae653f403364f4863c693283c7cad3c6f63fb1c2ebeade25740400000000ffffffff020000000000000000196a176465785837204020626974636f696e74616c6b2e6f726753890100000000001976a914784345e76ea29fd7bfe31f6f34622e154d0bb8fc88ac00000000

Code:
{
  "hex": "010000000183050588bc28f0ae653f403364f4863c693283c7cad3c6f63fb1c2ebeade2574040000006a47304402206eaf4d9c526a59bc391329dd62b6231035920ed23ba758a4d9b02d7738c0a77b0220404f00253e7d0202e64a7a8288dc83276218b91454d45ab618408f27b7135ba7012103c86e3c49a99dd688c6c6ad05d725b6a04ef19836b13d3e90ef282fc4f2f9ee71ffffffff020000000000000000196a176465785837204020626974636f696e74616c6b2e6f726753890100000000001976a914784345e76ea29fd7bfe31f6f34622e154d0bb8fc88ac00000000",
  "complete": true
}

4. And finally I broadcast the signed raw transaction.

Code:
bitcoin-cli sendrawtransaction 010000000183050588bc28f0ae653f403364f4863c693283c7cad3c6f63fb1c2ebeade2574040000006a47304402206eaf4d9c526a59bc391329dd62b6231035920ed23ba758a4d9b02d7738c0a77b0220404f00253e7d0202e64a7a8288dc83276218b91454d45ab618408f27b7135ba7012103c86e3c49a99dd688c6c6ad05d725b6a04ef19836b13d3e90ef282fc4f2f9ee71ffffffff020000000000000000196a176465785837204020626974636f696e74616c6b2e6f726753890100000000001976a914784345e76ea29fd7bfe31f6f34622e154d0bb8fc88ac00000000

Code:
b394e47f8141f725f25854d57e91fb67d91782dbe581b2f449990ba25a116d2d

5. Here is the result:

https://live.blockcypher.com/btc/tx/b394e47f8141f725f25854d57e91fb67d91782dbe581b2f449990ba25a116d2d/

Wink
legendary
Activity: 1442
Merit: 1186
Hey luv2drnkbr,

thanks for the follow up! I kinda feel bad for "getting paid" for this kind of information, because I believe it serves the greater good, but you may use 1BzW1ETp2qZsi6ogAufmGsadnQzJcmVXet.

Thanks a lot! Smiley

And please let me know, if any step is unclear or needs to be refined.

As a related note:

The RPC "createrawtransaction" of Bitcoin Core 0.12 will be extended, and directly supports to create OP_RETURN transactions as follows:

Code:
bitcoin-cli "createrawtransaction" '[{"txid":"hash","vout":n}, ...] '{"data": "0123..."}'

Could you do an example for what would be entered for "data" and "0123...."?  It looks like the same format for a receiving address as a raw transaction.

Code:
createrawtransaction '[{"txid":"","vout":}]' '{"receive_address":0.0008}'

So instead of entering a receiving address and an amount one would enter '{"data":40_bytes}' ?
legendary
Activity: 1106
Merit: 1026
Hey luv2drnkbr,

thanks for the follow up! I kinda feel bad for "getting paid" for this kind of information, because I believe it serves the greater good, but you may use 1BzW1ETp2qZsi6ogAufmGsadnQzJcmVXet.

Thanks a lot! Smiley

And please let me know, if any step is unclear or needs to be refined.

As a related note:

The RPC "createrawtransaction" of Bitcoin Core 0.12 will be extended, and directly supports to create OP_RETURN transactions as follows:

Code:
bitcoin-cli "createrawtransaction" '[{"txid":"hash","vout":n}, ...] '{"data": "0123..."}'
hero member
Activity: 793
Merit: 1026
From my point of view, this is a nice illustration, the op might honor dexX7 well with some coins.

I just now today found out about this thread!  I stopped checking it after a few weeks, because well, a few weeks with no replies I figured it was dead.  I have since gotten somebody else to teach me; however, that was a solid write-up and I'm happy to throw some coin to dexX7... except I can't find an address for him!  dexX7, thank you for that great write-up!  Do you have an address I can tip?
legendary
Activity: 1106
Merit: 1026
Is it possible to have multiple vout's using this schema? If so, is it possible to have multiple OP_RETURNs in one transaction?

Hi shamoons,

currently only one OP_RETURN output with a size of maximal 40 byte is considered as "accepted standard". Rather recently the default size of Bitcoin Core was raised to 80 byte, although I have no data whether this is adopted on a broader scale at this moment. The size is not a strict rule, and you'll find some OP_RETURN transactions with more than 200 byte on testnet, but on mainnet such transactions usually won't be relayed.
sr. member
Activity: 375
Merit: 255
just duplicate the part:

01                < Number of inputs
5d475fab463fee15d6d32b33151748cbc4eb7c8f06166f50ad77224ddc07bbc8  < Input transaction id
00000000          < Vout
00                < scriptSig length*
ffffffff          < Sequence number

why more op_return?
full member
Activity: 165
Merit: 100
Okay, I'll try. I created f3784ea6df802af5de7bfd8dd6af8eb07cf317b873f09f895586cd09892e897b a few minutes ago and will use this as example.

Start up your Bitcoin-Qt/bitcoind v0.9 client and go Help - Debug. Enter: "getrawtransaction f3784ea6df802af5de7bfd8dd6af8eb07cf317b873f09f895586cd09892e897b".

You will then see the transaction as hex*:

Code:
01000000015d475fab463fee15d6d32b33151748cbc4eb7c8f06166f50ad77224ddc07bbc8000000006b483045022100fd8c5227976363b79c6c2c72592e98148090ca26d89707f60dfaa19d5c59519f02207a34c47f2a55b9513d152520dd035fb9842d689c0c3350f4c0145e827e61604d01210391b373843e77f5ac1f05db4afb5151190e67cfee5a48f7925d71da7c5e919422ffffffff0100000000000000004e6a4c4b6f64617920697320466562203232203230313420616e642074686973206973206465785820402062697477617463682e636f2e2043686565727320616e64207374617920666c756666792100000000

This is the raw transaction with descriptions:

Code:
01000000          < Version
01                < Number of inputs
5d475fab463fee15d6d32b33151748cbc4eb7c8f06166f50ad77224ddc07bbc8  < Input transaction id
00000000          < Vout
00                < scriptSig length*
ffffffff          < Sequence number
01                < Number of outputs
0000000000000000  < Value
4e                < Push 78 byte (it's 78 hex encoded)
6a                < OP_RETURN
4c                < Push 76 byte (it's 76 hex encoded)
4974277320466562203232203230313420616e642074686973206973206465785820402062697477617463682e636f2e2043686565727320616c6c20616e64207374617920666c7566667921  < Payload with length of 76 byte
00000000          < Lock time

*I removed the actual scriptSig for this example.

You may notice that some data is flipped, for example the input transaction hash (compare: c8bb07dc4d2277ad506f16068f7cebc4cb481715332bd3d615ee3f46ab5f475d vs. 5d475fab463fee15d6d32b33151748cbc4eb7c8f06166f50ad77224ddc07bbc8).

To create an OP_RETURN transaction yourself, you may use this template:

Code:
0100000001AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABB00000000ffffffff0100000000000000004e6a4cCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC00000000

Replace AA...A with the input transaction hash flipped, BB with vout, CC...C with your payload/message.

Go back to your debug console and type "decoderawtransaction XXX", whereby XXX is your modified transaction hex. If everything is fine, this should return some information about your transaction.

You may adjust the payload length by changing the 4e and 4c. Use a calculator to convert the numbers.

http://brainwallet.org/#converter has a hex to text and vice versa converter.

When you are finished, type: "signrawtransaction XXX", whereby XXX is your transaction hex. It should show a longer hex followed by "complete".

Copy that longer hash and type "sendrawtransaction YYY", whereby YYY is the signed transaction hex.

Last note: make sure you use only an input with 0.0001-ish BTC. It will all be considered as miner fee unless you add more outputs.

Hope that helps. Smiley


Edit: max length is now 40 byte, so you must adjust the length.

Is it possible to have multiple vout's using this schema? If so, is it possible to have multiple OP_RETURNs in one transaction?
sr. member
Activity: 375
Merit: 255
mainnet
legendary
Activity: 1106
Merit: 1026
very interesting topic for me
but i typing getrawtransaction f3784ea6df802af5de7bfd8dd6af8eb07cf317b873f09f895586cd09892e897b 1 in my bitcoin-qt 0.10 and he says "No information available about transaction (code -5)"

Are you on testnet or mainnet? This is a mainnet transaction.
sr. member
Activity: 375
Merit: 255
very interesting topic for me
but i typing getrawtransaction f3784ea6df802af5de7bfd8dd6af8eb07cf317b873f09f895586cd09892e897b 1 in my bitcoin-qt 0.10 and he says "No information available about transaction (code -5)"
legendary
Activity: 1106
Merit: 1026
FWIW: you probably know the max. length to push was reduced to 40 byte on most pools.

A few days ago gidgreen published a small PHP tool to construct OP_RETURN transactions:

https://github.com/coinspark/php-OP_RETURN

That being said, abusing the blockchain as message storage is not very popular. Wink
b!z
legendary
Activity: 1582
Merit: 1010
dexX7 you da real MVP
legendary
Activity: 876
Merit: 1000
Etherscan.io
Thank you dexX7 
sr. member
Activity: 310
Merit: 250
Okay, I'll try. I created f3784ea6df802af5de7bfd8dd6af8eb07cf317b873f09f895586cd09892e897b a few minutes ago and will use this as example.

Start up your Bitcoin-Qt/bitcoind v0.9 client and go Help - Debug. Enter: "getrawtransaction f3784ea6df802af5de7bfd8dd6af8eb07cf317b873f09f895586cd09892e897b".

You will then see the transaction as hex*:

Code:
01000000015d475fab463fee15d6d32b33151748cbc4eb7c8f06166f50ad77224ddc07bbc8000000006b483045022100fd8c5227976363b79c6c2c72592e98148090ca26d89707f60dfaa19d5c59519f02207a34c47f2a55b9513d152520dd035fb9842d689c0c3350f4c0145e827e61604d01210391b373843e77f5ac1f05db4afb5151190e67cfee5a48f7925d71da7c5e919422ffffffff0100000000000000004e6a4c4b6f64617920697320466562203232203230313420616e642074686973206973206465785820402062697477617463682e636f2e2043686565727320616e64207374617920666c756666792100000000

This is the raw transaction with descriptions:

Code:
01000000          < Version
01                < Number of inputs
5d475fab463fee15d6d32b33151748cbc4eb7c8f06166f50ad77224ddc07bbc8  < Input transaction id
00000000          < Vout
00                < scriptSig length*
ffffffff          < Sequence number
01                < Number of outputs
0000000000000000  < Value
4e                < Push 78 byte (it's 78 hex encoded)
6a                < OP_RETURN
4c                < Push 76 byte (it's 76 hex encoded)
4974277320466562203232203230313420616e642074686973206973206465785820402062697477617463682e636f2e2043686565727320616c6c20616e64207374617920666c7566667921  < Payload with length of 76 byte
00000000          < Lock time

*I removed the actual scriptSig for this example.

You may notice that some data is flipped, for example the input transaction hash (compare: c8bb07dc4d2277ad506f16068f7cebc4cb481715332bd3d615ee3f46ab5f475d vs. 5d475fab463fee15d6d32b33151748cbc4eb7c8f06166f50ad77224ddc07bbc8).

To create an OP_RETURN transaction yourself, you may use this template:

Code:
0100000001AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABB00000000ffffffff0100000000000000004e6a4cCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC00000000

Replace AA...A with the input transaction hash flipped, BB with vout, CC...C with your payload/message.

Go back to your debug console and type "decoderawtransaction XXX", whereby XXX is your modified transaction hex. If everything is fine, this should return some information about your transaction.

You may adjust the payload length by changing the 4e and 4c. Use a calculator to convert the numbers.

http://brainwallet.org/#converter has a hex to text and vice versa converter.

When you are finished, type: "signrawtransaction XXX", whereby XXX is your transaction hash. It should show a longer hash followed by "complete".

Copy that longer hash and type "sendrawtransaction YYY", whereby YYY is the signed transaction hex.

Last note: make sure you use only an input with 0.0001-ish BTC. It will all be considered as miner fee unless you add more outputs.

Hope that helps. Smiley


Edit: max length is now 40 byte, so you must adjust the length.

I am just looking this info, how to create an OP_RETURN transaction. Thanks dexX7 for posting this, it is very useful tutorial.
legendary
Activity: 1106
Merit: 1026
So you basically want to double-spend(send same inputs twice)?

Hm? No. OP should use a fresh, unused input.
hero member
Activity: 935
Merit: 1002
So you basically want to double-spend(send same inputs twice)?
Pages:
Jump to: