Author

Topic: How to sign an OP_RETURN transaction with BitcoinJ (Read 1292 times)

newbie
Activity: 11
Merit: 0
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:


Code:
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 hashing with SHA256 is : "
                    + sha256.length + " bytes.");
    return transactionOutput;
}


And here are the steps that i have to finish in Main:

Code:
//create the OP_RETURN transaction in Main

            TransactionOutput output=dataOutput.createOpReturnTransaction(dataOutput.getTransaction(),dataOutput.getScriptbuilder());

         //sign the transaction and broadcast in Main ???



Second: Despite the fact that I have send bitcoins through the regtest network with the RPC : -regtest sendtoaddress n4MN27Lk7Yh3pwfjCiAbRXtRVjs4Uk67fG 10.00 balance in regtest.

in Java the wallet.getBalance() function returns zero concerning the balance of my wallet which has the n4MN27Lk7Yh3pwfjCiAbRXtRVjs4Uk67fG address

How it is possible to align my balance in regtest with this in BitcoinJ? I guess i will need balance in order to sign my OP_RETURN transaction.

Here is the output in the console: https://i.stack.imgur.com/rchS1.png



Jump to: