Inputs¶
A transaction's inputs say which UTXOs are being spent. Each input
points at a previous output by (transaction_id, index) and carries
the script that proves the spender is allowed to claim it.
Types involved¶
TransactionInput
previous_outpoint: TransactionOutpoint(transaction_id, index)
signature_script (filled at sign time)
sequence
sig_op_count
utxo: UtxoEntryReference # optional, but you almost always want it set
TransactionOutpoint—(transaction_id, index). The pointer to the output being spent.UtxoEntryReference— a cached copy of the spent output: its amount, lockup script, block DAA score, and coinbase flag.signature_script— the unlocking script. Empty ("") at build time; filled when you sign. See Signing.sequence— sequence number. Leave at0unless you have a specific protocol-level reason.sig_op_count— number of signature operations this input performs (1for Schnorr/ECDSA,>1for multisig). Feeds into mass calculation.
Build an input¶
From a UTXO dict returned by client.get_utxos_by_addresses(...):
from kaspa import TransactionInput, TransactionOutpoint, UtxoEntryReference
resp = await client.get_utxos_by_addresses({"addresses": [my_address]})
utxo = resp["entries"][0]
inp = TransactionInput(
previous_outpoint=TransactionOutpoint(
transaction_id=utxo["outpoint"]["transactionId"],
index=utxo["outpoint"]["index"],
),
signature_script="", # filled at sign time
sequence=0,
sig_op_count=1,
utxo=UtxoEntryReference(utxo),
)
Why inputs carry a UtxoEntryReference¶
Kaspa signs over the spent output's amount and lockup, not just the
outpoint. The SDK can't sign correctly without that context, so
TransactionInput.utxo attaches it directly — no node round-trip
needed.
Consequences:
- Forgetting
utxo=...when building manually breaks signing. - A signed transaction can move between processes (offline signer, co-signer, relay) without the receiver needing the source node — every input carries what's needed.
- The
Generatorhandles this for you. PassUtxoEntryReferences (or aUtxoContext— see UTXO Context) and it picks and wraps inputs internally.
Selecting which UTXOs to spend¶
The Generator (see Transaction Generator) handles
selection. When building manually, sum input values until the total
covers outputs + fee, then route the remainder to a change output.
See Outputs → Change.