How to sign an OP_RETURN transaction with BitcoinJ

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

 //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 of my console: enter image description here

http://ift.tt/2Aav9KQ

Comments

Popular posts from this blog

Need help to recover blpckchain.info wallet, my wife forgot her password and the brute force with btcrecover is not catching the password

When downloading the blockchain my application is become unusable, is there an issue with my code or am I using the BitcoinJ library incorrectly?

Mistakenly sent BTC from my personal wallet back to one of the exchange wallet addresses that I had received BTC from before - help recovering!