I am currently looking into the Bitcoin script. I want to create a transaction with one output with OP_RETURN and some data, and one output which pays coins to some address. I am confused, does OP_RETURN mark the whole transaction as invalid or just the output.

I am especially confused because the wiki is not clear on this issue: https://en.bitcoin.it/wiki/Script#Flow_control (says the whole transaction is marked as invalid) https://en.bitcoin.it/wiki/OP_RETURN (says just the output is marked as invalid)

1 Answer 1



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.

  • But doesn't that actually mean only the information in the second link is correct? If I have a transaction with 2 outputs. One with a OP_RETURN and one with the standard paytopubhash script. I can still use the second output as an input for another transaction?
    – Martin
    Commented Oct 29, 2016 at 12:28
  • Yes, you can spend the second output (if it's a standard pay-to-pubkey-hash script) by signing the spending transaction with the corresponding private key. The OP_RETURN one is permanently unspendable, so it is a good idea to send zero satoshis there. See this transaction blockchain.info/tx/… which is your exact use case. Notice the non-OP_RETURN output is marked spent, proving it's allowed.
    – maservant
    Commented Oct 29, 2016 at 14:22
  • Both links are correct. But the first one is about a transaction that spends an OP_RETURN. The second one is about an output that creates an OP_RETURN. Commented Oct 29, 2016 at 17:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.