We’re rewarding the question askers & reputations are being recalculated! Read more.
69

Note: I went out and learned about how the OP_RETURN opcode works at the byte level in a bitcoin transaction. I’m writing it here so that others can learn quickly. First, a brief history of why we’re even talking about OP_RETURN. Back in 2013 different players in the bitcoin ecosystem were trying to include bits of information into transactions so that they ...


13

I wrote a little demo program which puts a snippet of data into an OP_RETURN script. It requires a bitcoin instance that accepts RPC connections, though it could be implemented without that. You can find it on github here. It's been tested, but only on testnet. I'm going to go through the code and explain what it's doing. Start [...] logging.basicConfig() ...


11

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 ...


9

Here: var bitcoin = require('bitcoinjs-lib') data = new Buffer("Melons.") var tx = new bitcoin.TransactionBuilder() tx.addInput("aa94ab02c182214f090e99a0d57021caffd0f195a81c24602b1028b130b63e31", 0) tx.addOutput("some address", 15000) ret = bitcoin.script.compile( [ bitcoin.opcodes.OP_RETURN, data ]) tx.addOutput(ret, 0) key = bitcoin.ECPair....


9

If you want to write OP_RETURNs to the blockchain without getting into the internals of how transactions are built, an easy way is to use our libraries for PHP and Python: https://github.com/coinspark/php-OP_RETURN https://github.com/coinspark/python-OP_RETURN These support either sending individual transactions with one OP_RETURN attached, or else ...


8

10,000 bytes. See Bitcoin Core source code: https://github.com/bitcoin/bitcoin/blob/v0.17.0/src/script/script.h#L31-L32 https://github.com/bitcoin/bitcoin/blob/v0.17.0/src/script/interpreter.cpp#L299-L300


8

The maximum size of a block is 1MB. A block can be filled entirely with arbitrary data. Namecoin actually puts its extra data into the "coinbase" parameter, which is specifically designed to hold arbitrary data. Data put here is limited to 100 bytes, and this data will in the future be safely forgotten by most clients.


8

Can inject multiple OP_RETURN outputs in one transaction? At the protocol level, absolutely nothing prevents you from doing this. However, such a transaction would not be considered a 'standard' transaction and would not be relayed (propagated) through the network. Let's say, though, you were a miner yourself. Then you could mine a transaction with 100 ...


7

For a proof of existence, you do not actually need to store the data in the blockchain. Merely commiting to it, by using its hash in way that is later provably used, is enough. One such way is using a mechanism originally described as pay-to-contract. Warning: elliptic curve math follows. You start with any public key X (yours or someone elses). Then ...


6

How do I add metadata to the blockchain? Essentially, one of the output scripts should be OP_RETURN <the data you want to add> That's it. Let me give an example. Say you want to add the string "Melons." to the blockchain. Convert to binary "Melons." -> 4d656c6f6e732e Add the push-data-onto-stack command at the start. This is the length of your ...


5

NameCoin merged mining adds no more than 49 bytes to the size of the block. Namecoin messages aren't stored in the bitcoin block chain, instead the hash of the most recent namecoin block is stored in the Bitcoin block providing continuity between a potential hash and the Namecoin block chain. So yes it technically does "bloat" the Bitcoin blockchain but ...


5

If you want to retain any change, yes you will need two outputs to return unspent Bitcoin to yourself. If you are spending for example a 0.0001 BTC output, 0.0001 to fees, then a single 0 BTC OP_RETURN output would be valid.


5

The way Factom works, they store the merkle root of the various hashes on the blockchain in an OP_RETURN output. This amounts to 80 bytes in the OP_RETURN and the actual transaction is going to be on the order of 500 bytes. The way they scale is that they store the actual merkle tree elsewhere and only put the root into the blockchain, about once per block. ...


5

Factom stores data in a blockchain that's maintained by their network of federated servers. Tierion lets you create a verifiable record of any data or business process by anchoring your data to the blockchain. No altcoin required. We've created an open standard called Chainpoint for anchoring data in the blockchain. Like Factom, we use Merkle trees and ...


4

This is the PR that made OP_RETURN outputs standard: https://github.com/bitcoin/bitcoin/pull/2738 The commit: https://github.com/jgarzik/bitcoin/commit/a79342479f577013f2fd2573fb32585d6f4981b3 The current code: https://github.com/bitcoin/bitcoin/blob/v0.11.0/src/script/standard.cpp#L56-L58 if (GetBoolArg("-datacarrier", true)) ...


4

Not all miners accept transactions with null-data (OP_RETURN) outputs Not all nodes relay such transactions Are you sure that your null-data transaction is standard (for clients 0.9.x+) ? UPD: your output is 6a74686973206973206120746573740d0a and decoded to: OP_RETURN // 6a OP_DEPTH // 74 OP_ENDIF // 68 ... oups! This is non-standard output. Because ...


4

Currently, there are no BIPS (Bitcoin Improvement Proposals) that seek to increase the 80 byte limit as you can see here. Doing a cursory search on that repository, you can see that only a few mention OP_RETURN at all.


4

My understanding is that OP_RETURN was first introduced in v0.9.0 No, it was just changed to be standard in 0.9.0. If a transaction is nonstandard, miners running Bitcoin Core with default settings will not mine the transaction. OP_RETURN has been around since the beginning, in 0.1.0. This was the fragment that implemented OP_RETURN in 0.1.0: ...


4

Yes. Such transactions are valid and standard.


4

The limitation is a relay standard, but not a consensus rule. This can be modified on a per-node basis with $ bicoind -datacarriersize flag. The consensus rule that would limit this is the max block size, if I'm not mistaken. So, presumably, miners connected to the node that accepted that non-standard transaction mined that block, thus it was non-standard, ...


4

There is no way to enforce a rule regarding the nature of an output when an input is spent. You will have to enforce this off chain in some manner, perhaps through multisig schemes where one key is held by a rule engine that will only sign the tx if your requirements are met.


4

Coinbase transactions have some special rules not shared by other transactions: only one per block must be the first transaction in the block must have OP_RETURN output with witness commitment if block includes segwit transactions must have only one input the input must have the "coinbase" field instead of a scriptSig The "coinbase" field is where miners ...


4

The method described in the post has nothing to to with OP_RETURN, but is concerned with the SIGOP limits in a block. Each block has a limit on the number of SIGOPs that can be present in transactions in that block. Signature validation is a CPU intensive operation, and the limit exists to ensure that no block gets too big to validate on regular hardware. ...


3

Blockchain.info has buggy system which does not validate OP_RETURN outputs properly. Your transaction was pushed successfully using competent software. 71c3da4e13f5b61c2cf05e9b5a22f3be989142b870c1cf7779a1d7b3f139d422


3

As you can see, only 10.8% of nodes have upgraded to 0.11 and 29.3% of nodes use a pre-0.10 distribution. (Source: https://getaddr.bitnodes.io/dashboard/#user-agents) Considering that we don't know the hashing power of these nodes and don't know your definition of "swiftly included", there's no way to exactly answer your query. However, if you assume ...


3

You can make life easy by using one of our OP_RETURN libraries: PHP: https://github.com/coinspark/php-OP_RETURN Python: https://github.com/coinspark/python-OP_RETURN The code will also show you exactly how it's done.


3

I have forked the pybitcointools library to return a properly formatted OP_RETURN hex string, or insert the OP_RETURN into a raw hex transaction. My fork can be found here. The code is as follows: from bitcoin.pyspecials import safe_hexlify, from_string_to_bytes, from_int_to_byte, from_string_to_bytes def mk_opreturn(msg, rawtx=None, json=0): def ...


3

So is it one OP_RETURN parameter for each bitcoin transaction or per each input/output address? One OP_RETURN output per transaction regardless of the number of inputs and outputs is standard for 0.9.x bitcoin core clients. If its each transaction, so its safe to say its about .0001 btc to send 40 byte message? Yes, but you should not do it without ...


3

You can't make an OP_RETURN-based output out to any specific address, since the OP_RETURN opcode marks an output as invalid (thus provably unspendable). In fact, an OP_RETURN-based output will not even enter the UTXO. A zero amount is okay (and even encouraged) for OP_RETURN. The OP_RETURN is paid for via the fee; putting a non-zero amount in OP_RETURN ...


3

Both. Transaction output scripts are only executed at the time they are attempted to be spent. If you try to spend an OP_RETURN output, the spending transaction is invalid, as this instruction immediately fails the execution. As a result, OP_RETURN outputs (not the transactions they are in) are unspendable.


Only top voted, non community-wiki answers of a minimum length are eligible