0

I'd like my Web3 wallet to list all transactions to: and from: this.state.account in chronological order, currently I am getting a split of transactions, from: listed first and then to: listed second, Is there a way to list to: and from: all in order so the results flow and are not split? If I exclude the filter: altogether, I get all transactions on the blockchain which is in the correct order! -But it lists all transactions from all wallets, I only need the to: and from: this.state.account.

My goal is to list all the transactions of this.state.account in the order they occurred, without listing the activity of other addresses on the blockchain.

Here's what the split results look like showing received (top three tx) and sent (bottom six tx):

enter image description here

Defining const:

    const transactions = (await Promise.all([
      Token123.getPastEvents('Transfer', { fromBlock: 0, toBlock: 'latest', filter: { from: this.state.account } }), 
      Token123.getPastEvents('Transfer', { fromBlock: 0, toBlock: 'latest', filter: { to: this.state.account } })])).flat()
    this.setState({ transactions: transactions })

Here is how I am viewing the results:

                  <tbody>
                { this.state.transactions.slice().reverse().map((tx, key) => {
                  return (
                    <tr key={key} >
                      <td>{tx.returnValues.to}</td>
                      <td>{window.web3.utils.fromWei(tx.returnValues.value.toString(), 'Ether')}</td>
                    </tr>
                  )
                }) }
              </tbody>

Using: "web3": "1.0.0-beta.55"

0

Replace this:

this.state.transactions.slice().reverse()

With this:

this.state.transactions.sort((a, b) => a.blockNumber < b.blockNumber)
2
  • Perfect, thanks!! – Luc1d Apr 11 '20 at 14:47
  • @Luc1d: NP. BTW, I realized what was missing in the answer that I gave you on your earlier message. The result was an array containing two arrays. You could resolve that with flat() as you probably did, or with ..., which I personally like better, so updated that answer accordingly. – goodvibration Apr 11 '20 at 15:02

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.