<p>You can't make an <code>OP_RETURN</code>-based output out to any specific address, since the <code>OP_RETURN</code> opcode marks an output as invalid (thus provably unspendable). In fact, an <code>OP_RETURN</code>-based output will not even enter the <code>UTXO</code>.</p>

<p>A zero amount is okay (and even encouraged) for <code>OP_RETURN</code>.  The <code>OP_RETURN</code> is paid for via the fee; putting a non-zero amount in <code>OP_RETURN</code> would just destroy bitcoins, so the miners do not profit from mining it.</p>

<p>However, you can create a transaction that has multiple output scripts: One can be a standard <code>P2PKH</code> of the form <code>OP_DUP OP_HASH160 &lt;pubKeyHash&gt; OP_EQUALVERIFY OP_CHECKSIG</code> while the other can be an output with <code>OP_RETURN</code>. Just call <code>addOutput</code> twice, once with an address and the amount desired, and a second time with parameters for an OP_RETURN script (and a non-zero output value, I would presume).</p>

CC BY-SA 3.0
2016-06-06T13:25:05.187Z
2016-06-06T13:25:05.187Z
jgm
<p>How do I formulate a transaction with <code>OP_RETURN</code> to <em>a particular address</em> using the <em>bitcoinj</em> library?</p>

<pre><code>SendRequest req;
Transaction transaction = new Transaction(Main.getNetWorkParameters());
transaction.addOutput(Coin.ZERO, ScriptBuilder.createOpReturnScript(
    "thanks for the coins".toString().getBytes()));

// add a receiving address for this transaction
req = SendRequest.forTx(transaction);
</code></pre>

<transactions><bitcoind><bitcoinj><op-return>
Transaction with `OP_RETURN` to a particular address
jgm
# Transaction with `OP_RETURN` to a particular address

(Asked by: username_0 on 2016-06-05)

How do I formulate a transaction with `OP_RETURN` to *a particular address* using the *bitcoinj* library?

```
SendRequest req;
Transaction transaction = new Transaction(Main.getNetWorkParameters());
transaction.addOutput(Coin.ZERO, ScriptBuilder.createOpReturnScript(
    "thanks for the coins".toString().getBytes()));

// add a receiving address for this transaction
req = SendRequest.forTx(transaction);

```

**Tags:** transactions, bitcoind, bitcoinj, op-return


---

## 1 answers

### Answer by username_0 on 2016-06-06. Score: 3 | Accepted answer

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` would just destroy bitcoins, so the miners do not profit from mining it.

However, you can create a transaction that has multiple output scripts: One can be a standard `P2PKH` of the form `OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG` while the other can be an output with `OP_RETURN`. Just call `addOutput` twice, once with an address and the amount desired, and a second time with parameters for an OP\_RETURN script (and a non-zero output value, I would presume).


---

