I work with a Wallet app and using the BitcoinJ for programming. I need to find the last executed transaction from the wallet. In the org.bitcoinj.core.Wallet class, I see there is a method getTransactionsByTime() that returns list of all non-dead, active transactions ordered by recency as List<Transaction>.

Will I access the most recent transaction with index 0 or the last index? I have made some experiments and I likely think that would be with index of 0. Because, it returns the sending info and I have done some recently, but, still weird as the amount doesn't match with performed.

While I have tried with the last index, I think that's obviously not the case as that's returns the info of the incoming transactions.

The way I find the most recent transaction,

    Transaction ts = size > 0 ? getTransactions().get(0) : null;
    this.transaction = addTransactionHistory(ts);

I print the transaction as the most recent one in console.

1 Answer 1


The first transaction in the list should be the newest one.

The best way to answer such questions is always to read the source code. getTransactionsByTime calls getRecentTransactions, and there is a comment:

Returns an list of N transactions, ordered by increasing age.

You can trace down to find the critical minus sign that ensures this.

You can also find a test that explicitly verifies it works as documented.

  • Thanks a lot for this answer. I'm new to cryptocurrency and developing a customized wallet.
    – Arefe
    Jun 16, 2017 at 8:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.