UtxoContext is a class that provides a way to track addresses activity on the Kaspa network. When an address is registered with UtxoContext it aggregates all UTXO entries for that address and emits events when any activity against these addresses occurs.

UtxoContext constructor accepts IUtxoContextArgs interface that can contain an optional id parameter. If supplied, this id parameter will be included in all notifications emitted by the UtxoContext as well as included as a part of ITransactionRecord emitted when transactions occur. If not provided, a random id will be generated. This id typically represents an account id in the context of a wallet application. The integrated Wallet API uses UtxoContext to represent wallet accounts.

Exchanges: if you are building an exchange wallet, it is recommended to use UtxoContext for each user account. This way you can track and isolate each user activity (use address set, balances, transaction records).

UtxoContext maintains a real-time cumulative balance of all addresses registered against it and provides balance update notification events when the balance changes.

The UtxoContext balance is comprised of 3 values:

  • mature: amount of funds available for spending.
  • pending: amount of funds that are being received.
  • outgoing: amount of funds that are being sent but are not yet accepted by the network.

Please see IBalance interface for more details.

UtxoContext can be supplied as a UTXO source to the transaction Generator allowing the Generator to create transactions using the UTXO entries it manages.

IMPORTANT: UtxoContext is meant to represent a single account. It is not designed to be used as a global UTXO manager for all addresses in a very large wallet (such as an exchange wallet). For such use cases, it is recommended to perform manual UTXO management by subscribing to UTXO notifications using RpcClient.subscribeUtxosChanged and RpcClient.getUtxosByAddresses.

Constructors

Properties

balance: Balance

Current Balance of the UtxoContext.

balanceStrings: BalanceStrings

Current BalanceStrings of the UtxoContext.

isActive: boolean
matureLength: number

Obtain the length of the mature UTXO entries that are currently managed by the UtxoContext.

Methods

  • Clear the UtxoContext. Unregister all addresses and clear all UTXO entries. IMPORTANT: This function must be manually called when disconnecting or re-connecting to the node (followed by address re-registration).

    Returns Promise<void>

  • Returns void

  • Returns a range of mature UTXO entries that are currently managed by the UtxoContext and are available for spending.

    NOTE: This function is provided for informational purposes only. You should not manage UTXO entries manually if they are owned by UtxoContext.

    The resulting range may be less than requested if UTXO entries have been spent asynchronously by UtxoContext or by other means (i.e. UtxoContext has received notification from the network that UtxoEntries have been spent externally).

    UtxoEntries are kept in in the ascending sorted order by their amount.

    Parameters

    • from: number
    • to: number

    Returns UtxoEntryReference[]

    • Return copy of self without private attributes.

    Returns Object

  • Return stringified version of self.

    Returns string

  • Performs a scan of the given addresses and registers them in the context for event notifications.

    Parameters

    • addresses: (string | Address)[]
    • Optional optional_current_daa_score: bigint

    Returns Promise<void>

  • Unregister a list of addresses from the context. This will stop tracking of these addresses.

    Parameters

    Returns Promise<void>

Generated using TypeDoc