<blockquote>
<p>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</p>
</blockquote>
<p>I think you can build the input based on a previous transaction output (outpoint) as follows:</p>
<pre><code>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);
</code></pre>
<p>Not sure if this is the best ways to do it.</p>
<p>EDIT: This does the same as the code above.</p>
<pre><code>transaction.addInput(Sha256Hash.wrap(txId), index, ScriptBuilder.createEmpty());
</code></pre>

CC BY-SA 4.0
2020-11-13T16:00:01.840Z
2020-11-22T13:29:25.047Z
2020-11-22T13:29:25.047Z
fatdoor
<p>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.</p>
<p>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 &quot;parent&quot; parameter, but i'm failing. This is my snippet:</p>
<pre><code>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)
</code></pre>

<transactions><bitcoinj><java><raw>
Create Raw Transaction in BitcoinJ offline starting from UTXO info
Andrean
# Create Raw Transaction in BitcoinJ offline starting from UTXO info

(Asked by: username_0 on 2020-11-13)

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)

```

**Tags:** transactions, bitcoinj, java, raw


---

## 1 answers

### Answer by username_1 on 2020-11-13. Score: 0 | Accepted answer

> 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());

```


---

