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).
outputs
property
writable
¶
outputs: list[TransactionOutput]
The list of transaction outputs defining value destinations.
__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. |
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:
|
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:
|