How to sign a transaction using BitcoinJ

2

I am having problem signing the transaction using BitcoinJ library without the Wallet instance, I only have the Transaction class instance and the ECKey in order to sign the transaction.

Is there a way to implement it ?

Firass Obaid

Posted 2015-04-29T17:23:15.187

Reputation: 121

Answers

0

Good day. You shoud have list of unspent outputs, for adding them into inputs of your tx. Also you should generate private keys and use special privKey for every input you have.

Try it out:

TransactionOutPoint outPoint = new TransactionOutPoint(params, utxo.getIndex(), utxo.getHash());
byte[] privKeyBytes = HEX.decode(privKeyAsHex);
ECKey ecKey = ECKey.fromPrivate(privKeyBytes);

transaction.addSignedInput(outPoint, utxo.getScript(), ecKey, Transaction.SigHash.ALL, true);

Timur Panzhiev

Posted 2015-04-29T17:23:15.187

Reputation: 31