<p>The first transaction in the list should be the newest one.</p>

<p>The best way to answer such questions is always to read the source code. <a href="https://github.com/bitcoinj/bitcoinj/blob/943a139d0846afb4f1432a1cfcd3949f52dede28/core/src/main/java/org/bitcoinj/wallet/Wallet.java#L2918" rel="nofollow noreferrer"><code>getTransactionsByTime</code></a> calls <a href="https://github.com/bitcoinj/bitcoinj/blob/943a139d0846afb4f1432a1cfcd3949f52dede28/core/src/main/java/org/bitcoinj/wallet/Wallet.java#L2930" rel="nofollow noreferrer"><code>getRecentTransactions</code></a>, and there is a <a href="https://github.com/bitcoinj/bitcoinj/blob/943a139d0846afb4f1432a1cfcd3949f52dede28/core/src/main/java/org/bitcoinj/wallet/Wallet.java#L2923" rel="nofollow noreferrer">comment</a>:</p>

<blockquote>
  <p>Returns an list of N transactions, ordered by increasing age.</p>
</blockquote>

<p>You can trace down to find <a href="https://github.com/bitcoinj/bitcoinj/blob/c24ef97ac036fcb3ec7b20597968c4a4984076b8/core/src/main/java/org/bitcoinj/core/Transaction.java#L73" rel="nofollow noreferrer">the critical minus sign</a> that ensures this.</p>

<p>You can also find <a href="https://github.com/bitcoinj/bitcoinj/blob/6841fceabc380301a2a85d616aea491bf7ee3de5/core/src/test/java/org/bitcoinj/wallet/WalletTest.java#L1457" rel="nofollow noreferrer">a test</a> that explicitly verifies it works as documented.</p>

CC BY-SA 3.0
2017-06-16T08:54:05.817Z
Thanks a lot for this answer. I'm new to cryptocurrency and  developing a customized wallet.
Arefe
CC BY-SA 3.0
2017-06-15T13:13:22.203Z
2017-06-15T13:13:22.203Z
Nate Eldredge
<p>I work with a Wallet app and using the <code>BitcoinJ</code> for programming. I need to find the last executed transaction from the wallet. In the <code>org.bitcoinj.core.Wallet</code> class, I see there is a method <code>getTransactionsByTime()</code> that returns list of all non-dead, active transactions ordered by recency as <code>List&lt;Transaction&gt;</code>. </p>

<p>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 <code>index of 0</code>. Because, it returns the sending info and I have done some recently, but, still weird as the amount doesn't match with performed. </p>

<p>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. </p>

<p>The way I find the most recent transaction, </p>

<pre><code>    transactions.addAll(wallet.getTransactionsByTime());    
    Transaction ts = size &gt; 0 ? getTransactions().get(0) : null;
    this.transaction = addTransactionHistory(ts);
</code></pre>

<p>I print the <code>transaction</code> as the most recent one in console. </p>

<bitcoinj><java>
How to get the last executed transaction?
Arefe
# How to get the last executed transaction?

(Asked by: username_0 on 2017-06-15)

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,

```
    transactions.addAll(wallet.getTransactionsByTime());    
    Transaction ts = size > 0 ? getTransactions().get(0) : null;
    this.transaction = addTransactionHistory(ts);

```

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

**Tags:** bitcoinj, java


---

## 1 answers

### Answer by username_1 on 2017-06-15. Score: 1 | Accepted answer

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`](https://github.com/bitcoinj/bitcoinj/blob/943a139d0846afb4f1432a1cfcd3949f52dede28/core/src/main/java/org/bitcoinj/wallet/Wallet.java#L2918) calls [`getRecentTransactions`](https://github.com/bitcoinj/bitcoinj/blob/943a139d0846afb4f1432a1cfcd3949f52dede28/core/src/main/java/org/bitcoinj/wallet/Wallet.java#L2930), and there is a [comment](https://github.com/bitcoinj/bitcoinj/blob/943a139d0846afb4f1432a1cfcd3949f52dede28/core/src/main/java/org/bitcoinj/wallet/Wallet.java#L2923):

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

You can trace down to find [the critical minus sign](https://github.com/bitcoinj/bitcoinj/blob/c24ef97ac036fcb3ec7b20597968c4a4984076b8/core/src/main/java/org/bitcoinj/core/Transaction.java#L73) that ensures this.

You can also find [a test](https://github.com/bitcoinj/bitcoinj/blob/6841fceabc380301a2a85d616aea491bf7ee3de5/core/src/test/java/org/bitcoinj/wallet/WalletTest.java#L1457) that explicitly verifies it works as documented.

> **Comments:**
> **username_0**: Thanks a lot for this answer. I'm new to cryptocurrency and  developing a customized wallet.  

---

