Paulo Kussler
Paulo Kussler

Reputation: 183

How to retrieve the Transaction ID (txhash) for a transaction list in Corda

How can I retrieve a list of transaction information and their respective id (txhash).

I have a State and retrieve information with Query, but I need the transaction ID (txhash) for each transaction.

Use Kotlin.

Upvotes: 0

Views: 213

Answers (1)

Adel Rustum
Adel Rustum

Reputation: 2548

The query returns a StateAndRef which is as the name implies:

  1. Your state.
  2. A StateRef: Every state is a result of a transaction, but the transaction might have produced multiple states (outputs); so the unique "identity" (or state ref) of a state is the combination of the transaction Id and the index of that state in the list of transaction's outputs (so if your transaction with Id XYZ had 3 outputs, and your state was the second output; the StateRef would be XYZ, 1).

Anyway, to answer your question; if you have a StateAndRef myStateAndRef, then you can get the transaction Id with myStateAndRef.getRef().getTxhash().

Upvotes: 3

Related Questions