Hello IOTA Forum

Fetch the last transaction occurred to a specific address

https://forum.helloiota.com/Topic19536.aspx

By yehia67 - 29 Nov 2019

Hello everyone, I have a question on how to fetch the last transaction that occurred to a given address and I don't have the bundle.
I tried this javascript code
findTransactionObjects({ addresses: [userAddress] }).then(response => {//somecode})

I supposed that the last element of response array will be the last transaction but its not. I need to fetch data from the last transaction occurred could anyone help me with that? Thanks in advance.
By satish.joshi - 2 Jun 2020

yehia67 - 29 Nov 2019
Hello everyone, I have a question on how to fetch the last transaction that occurred to a given address and I don't have the bundle.
I tried this javascript code
findTransactionObjects({ addresses: [userAddress] }).then(response => {//somecode})

I supposed that the last element of response array will be the last transaction but its not. I need to fetch data from the last transaction occurred could anyone help me with that? Thanks in advance.

Hi @yehia67, Directly there's no way you can fetch the last transaction associated with address but you can achieve this by doing some little modification on the mentioned API by like this :

iota.findTransactionObjects({ addresses: [userAddress] })
   .then(transactions => {
    //Sorting Array on Timestamp
    transactions.sort(function (x, y) {
      return y.timestamp - x.timestamp;
    });


After applying this sorting you can have the last transaction as the first element on the returned array I guess.