Bitcoin Asked by Andrean on December 19, 2020
I would to create offline Raw Transaction (without signing it) in BitcoinJ. The information I know about the inout is UTXO’s hash, index, amount, address, and script. I also know the receiver address of the final transaction, the change address, the amount and the fee.
I’m fighting with the TransactionOutput constructors to build the input for my transaction. I don’t know where to set UTXO hash and index – i think in the "parent" parameter, but i’m failing. This is my snippet:
Transaction parent = ???
Coin value = Coin.valueOf(satoshi(utxo.getAmount()));
Address to = Address.fromBase58(params, utxo.getOwnerAddress());
//where do i put utxo hash and index?
TransactionOutput input = new TransactionOutput(params, parent, value, to);
tx.addInput(input)
I'm fighting with the TransactionOutput constructors to build the input for my transaction. I don't know where to set UTXO hash and index
I think you can build the input based on a previous transaction output (outpoint) as follows:
byte[] scriptBytes = {};
Sha256Hash vinTxId = Sha256Hash.wrap(txId);
TransactionOutPoint outpoint = new TransactionOutPoint(params, index, vinTxId);
Coin value = null;
TransactionInput input = new TransactionInput(params, transaction, scriptBytes, outpoint, value);
transaction.addInput(input);
Not sure if this is the best ways to do it.
EDIT: This does the same as the code above.
transaction.addInput(Sha256Hash.wrap(txId), index, ScriptBuilder.createEmpty());
Correct answer by fatdoor on December 19, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP