Skip to content

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.

gas property writable

gas: int

The gas limit for smart contract execution.

id property

id: str

The transaction ID (hash) as a hex string.

inputs property writable

inputs: list[TransactionInput]

The list of transaction inputs spending previous outputs.

lock_time property writable

lock_time: int

The transaction lock time (DAA score or Unix timestamp before which the transaction cannot be included).

mass property writable

mass: int

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.

payload property writable

payload: str

The transaction payload data as a hex string.

storage_mass property writable

storage_mass: int

The transaction storage mass used for fee calculation.

subnetwork property

subnetwork: str

The subnetwork identifier as a hex string.

version property writable

version: int

The transaction version number.

__eq__

__eq__(other: Transaction) -> bool

__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: int

inputs

List of transaction inputs.

TYPE: Sequence[TransactionInput]

outputs

List of transaction outputs.

TYPE: Sequence[TransactionOutput]

lock_time

Lock time (block DAA score or timestamp).

TYPE: int

subnetwork_id

Subnetwork identifier (hex string or bytes).

TYPE: Binary

gas

Gas limit for smart contract execution.

TYPE: int

payload

Optional transaction payload data.

TYPE: Binary

mass

Transaction mass (for fee calculation).

TYPE: int

RETURNS DESCRIPTION
Transaction

A new Transaction instance.

TYPE: Transaction

RAISES DESCRIPTION
Exception

If the subnetwork_id is invalid or transaction creation fails.

__repr__

__repr__() -> str

The detailed string representation.

RETURNS DESCRIPTION
str

The Transaction as a repr string.

TYPE: str

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: str | NetworkType

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: Hash

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: dict

RETURNS DESCRIPTION
Transaction

A new Transaction instance.

TYPE: Transaction

RAISES DESCRIPTION
KeyError

If required keys are missing.

ValueError

If values are invalid.

is_coinbase

is_coinbase() -> bool

Check if this is a coinbase transaction.

RETURNS DESCRIPTION
bool

True if this is a coinbase (mining reward) transaction.

TYPE: bool

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: Sequence[GenesisCovenantGroup]

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

subnetwork_id(value: str) -> None

Set the subnetwork identifier.

PARAMETER DESCRIPTION
value

The subnetwork ID as a hex string.

TYPE: str

RAISES DESCRIPTION
Exception

If the hex string is invalid or has incorrect length.

to_dict

to_dict() -> 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: dict