Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: drawingthesun on April 24, 2014, 03:38:50 PM



Title: How to add arbitrary 40 byte data per transaction.
Post by: drawingthesun on April 24, 2014, 03:38:50 PM
How do you add 40 bytes of data into the blockchain?


Title: Re: How to add arbitrary 40 byte data per transaction.
Post by: TierNolan on April 24, 2014, 03:45:31 PM
How do you add 40 bytes of data into the blockchain?

You can use the OP_RETURN opcode.  

An output that has a spending script of "OP_RETURN <up to 40 bytes>" will be accepted by miners.

It is not spendable though, since OP_RETURN just means mark output as invalid.

There are other ways to do it, but using OP_RETURN means you aren't "polluting" the chain.  Since the output is known not to be spendable, it doesn't have to be remembered in RAM.  It is still remembered on disk though.


Title: Re: How to add arbitrary 40 byte data per transaction.
Post by: drawingthesun on April 24, 2014, 04:02:25 PM
How do you add 40 bytes of data into the blockchain?

You can use the OP_RETURN opcode.  

An output that has a spending script of "OP_RETURN <up to 40 bytes>" will be accepted by miners.

It is not spendable though, since OP_RETURN just means mark output as invalid.

There are other ways to do it, but using OP_RETURN means you aren't "polluting" the chain.  Since the output is known not to be spendable, it doesn't have to be remembered in RAM.  It is still remembered on disk though.

Thanks :)


Title: Re: How to add arbitrary 40 byte data per transaction.
Post by: Realpra on July 15, 2014, 06:44:30 AM
Won't the sent amount just all go towards miners fees or is the "correct way" of putting data really to create unspendable dust?


Title: Re: How to add arbitrary 40 byte data per transaction.
Post by: TimS on July 15, 2014, 12:20:45 PM
Won't the sent amount just all go towards miners fees or is the "correct way" of putting data really to create unspendable dust?
The OP_RETURN output can be 0 value. If your input(s) are larger than the fee you need to pay, you can put the rest of the money into an ordinary output, as change. Or if you have an input that's just the right size, you can include just the one output, e.g. as done in this transaction https://blockchain.info/tx/064c3364055cc2d862f9320279e486b95a169806aac315333bb035a5ee684891

I wouldn't call it "dust" since it's 0 value and known-pruneable. It can't be spent, but it's 0 value so it didn't destroy any bitcoins in the process of creating it.


Title: Re: How to add arbitrary 40 byte data per transaction.
Post by: DeathAndTaxes on July 15, 2014, 09:13:16 PM
Won't the sent amount just all go towards miners fees or is the "correct way" of putting data really to create unspendable dust?

The most common method is to create an otherwise normal txn (with any amount of fees you desire) and then ADD a zero value OP_RETURN output.  They can be pruned because the only outputs which are needed to validate future outputs are spendable outputs.  Normal outputs are pruned once they are spent as a spent output is no longer spendable.  OP_RETURN outputs are by definition never spendable so they can be pruned immediately.

To validate transactions requires maintaining a copy of the UTXO.  This is a more critical resources than the raw blockchain.  Your node doesn't use raw blocks locally for anything other than building the UTXO.  The UTXO is used to validate all future txns and blocks.  OP_RETURN can be excluded from the UTXO as are outputs once they are spent.