Transaction (Class)¶
A Kaspa transaction.
Represents a complete transaction with inputs, outputs, and metadata. Transactions are the fundamental unit of value transfer on the Kaspa network.
inputs
property
writable
¶
inputs: list[TransactionInput]
The list of transaction inputs spending previous outputs.
lock_time
property
writable
¶
The transaction lock time (DAA score or Unix timestamp before which the transaction cannot be included).
mass
property
writable
¶
The transaction mass used for fee calculation.
Alias of storage_mass, retained for compatibility with the WASM SDK
and earlier releases of this package.
outputs
property
writable
¶
outputs: list[TransactionOutput]
The list of transaction outputs defining value destinations.
storage_mass
property
writable
¶
The transaction storage mass used for fee calculation.
__new__
¶
__new__(version: int, inputs: Sequence[TransactionInput], outputs: Sequence[TransactionOutput], lock_time: int, subnetwork_id: Binary, gas: int, payload: Binary, mass: int) -> Transaction
Create a new transaction.
| PARAMETER | DESCRIPTION |
|---|---|
version
|
Transaction version number.
TYPE:
|
inputs
|
List of transaction inputs.
TYPE:
|
outputs
|
List of transaction outputs.
TYPE:
|
lock_time
|
Lock time (block DAA score or timestamp).
TYPE:
|
subnetwork_id
|
Subnetwork identifier (hex string or bytes).
TYPE:
|
gas
|
Gas limit for smart contract execution.
TYPE:
|
payload
|
Optional transaction payload data.
TYPE:
|
mass
|
Transaction mass (for fee calculation).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Transaction
|
A new Transaction instance.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
Exception
|
If the subnetwork_id is invalid or transaction creation fails. |
__repr__
¶
The detailed string representation.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The Transaction as a repr string.
TYPE:
|
addresses
¶
addresses(network_type: str | NetworkType) -> list[Address]
Extract unique addresses from transaction inputs.
| PARAMETER | DESCRIPTION |
|---|---|
network_type
|
The network type to use for address encoding.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Address]
|
list[Address]: List of unique addresses referenced by inputs. |
finalize
¶
finalize() -> Hash
Finalize the transaction and compute its ID.
| RETURNS | DESCRIPTION |
|---|---|
Hash
|
The computed transaction ID.
TYPE:
|
from_dict
classmethod
¶
from_dict(dict: dict) -> Transaction
Create a Transaction from a dictionary.
| PARAMETER | DESCRIPTION |
|---|---|
dict
|
Dictionary containing transaction fields with keys: - 'id' (str): Transaction ID as hex string - 'version' (int): Transaction version number - 'inputs' (list[dict]): List of input dictionaries - 'outputs' (list[dict]): List of output dictionaries - 'lockTime' (int): Lock time value - 'subnetworkId' (str): Subnetwork ID as hex string - 'gas' (int): Gas limit - 'payload' (str): Payload as hex string - 'mass' (int): Transaction mass
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Transaction
|
A new Transaction instance.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If required keys are missing. |
ValueError
|
If values are invalid. |
is_coinbase
¶
Check if this is a coinbase transaction.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if this is a coinbase (mining reward) transaction.
TYPE:
|
populate_genesis_covenants
¶
populate_genesis_covenants(groups: Sequence[GenesisCovenantGroup]) -> None
Populate genesis covenant bindings for multiple output groups.
For each group, computes the covenant id from the authorizing input outpoint and the group's output list, then sets that binding on all listed outputs. All groups are validated before the transaction is mutated.
| PARAMETER | DESCRIPTION |
|---|---|
groups
|
The genesis covenant groups to populate.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
Exception
|
If a group references a non-existent input or output, output indices are not strictly increasing, outputs overlap across groups, or a targeted output already has a covenant binding. |
subnetwork_id
¶
Set the subnetwork identifier.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The subnetwork ID as a hex string.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
Exception
|
If the hex string is invalid or has incorrect length. |
to_dict
¶
Get a dictionary representation of the Transaction. Note that this creates a second separate object on the Python heap.
| RETURNS | DESCRIPTION |
|---|---|
dict
|
the Transaction in dictionary form.
TYPE:
|