Posts

Showing posts with the label How to sign an OP_RETURN transaction with BitcoinJ

How to sign an OP_RETURN transaction with BitcoinJ

Image
How to sign an OP_RETURN transaction with BitcoinJ I want to create and sign an OP_RETURN transaction and broadcasting to my Regtest network. I face up two problems: First: I have created successfully the transaction output but how to sign and broadcast my transaction to the regtest network? Here is my code for creating the output: public TransactionOutput createOpReturnTransaction(org.bitcoinj.core.Transaction tx, ScriptBuilder sb) { String myData = Main.resultHash; byte[] sha256 = org.apache.commons.codec.digest.DigestUtils .sha256(myData); myScript = sb.op(ScriptOpCodes.OP_RETURN).data(sha256).build(); TransactionOutput transactionOutput = tx.addOutput( org.bitcoinj.core.Transaction.MIN_NONDUST_OUTPUT, myScript); System.out.println("My script is :" + myScript); System.out.println("My transaction output is : " + transactionOutput); System.out .println("The size of my message after hashin...