Bitcoin Forum
May 04, 2024, 05:22:11 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Transaction with `OP_RETURN` to a particular address  (Read 779 times)
jgmBitcoin (OP)
Newbie
*
Offline Offline

Activity: 18
Merit: 8


View Profile
June 05, 2016, 11:32:28 PM
 #1

How do I formulate a Transaction with OP_RETURN to a particular address using Bitcoinj library.

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);
1714843331
Hero Member
*
Offline Offline

Posts: 1714843331

View Profile Personal Message (Offline)

Ignore
1714843331
Reply with quote  #2

1714843331
Report to moderator
You can see the statistics of your reports to moderators on the "Report to moderator" pages.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714843331
Hero Member
*
Offline Offline

Posts: 1714843331

View Profile Personal Message (Offline)

Ignore
1714843331
Reply with quote  #2

1714843331
Report to moderator
hexafraction
Sr. Member
****
Offline Offline

Activity: 392
Merit: 259

Tips welcomed: 1CF4GhXX1RhCaGzWztgE1YZZUcSpoqTbsJ


View Profile
June 05, 2016, 11:55:36 PM
Merited by ABCbits (2)
 #2

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.

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

I have recently become active again after a long period of inactivity. Cryptographic proof that my account has not been compromised is available.
johoe
Full Member
***
Offline Offline

Activity: 217
Merit: 238


View Profile
June 06, 2016, 09:39:52 AM
Merited by ABCbits (1)
 #3

for an OP_RETURN script (and a non-zero output value, I would presume).

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.

Donations to 1CF62UFWXiKqFUmgQMUby9DpEW5LXjypU3
hexafraction
Sr. Member
****
Offline Offline

Activity: 392
Merit: 259

Tips welcomed: 1CF4GhXX1RhCaGzWztgE1YZZUcSpoqTbsJ


View Profile
June 06, 2016, 07:42:17 PM
 #4

for an OP_RETURN script (and a non-zero output value, I would presume).

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.

Ah, my mistake. I assumed for some reason that a zero-value output was invalid (bad assumption). Thanks for explaining to me so I know now.

I have recently become active again after a long period of inactivity. Cryptographic proof that my account has not been compromised is available.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!