Building a simplified etherscan - How should I get the historical data

I started watching the etherscan clone youtube series.
I didn’t manage to get any data from the getTransactions cloud function when trying to query a random ethereum address, no errors, just got an empty array.

When I tried fetching an ethereum address that had transactions stored in the moralis server database, I got the data. But you shouldn’t have to have the historical transactions stored in the moralis database, right? Or?

Any reason I shouldn’t use speedynodes archive?
Is the way Jeremy does it in cloning etherescan series the way to do it?

hi - please post all code and explain the issue that way, impossible to help just reading explanation without code

Maybe I am expressing myself poorly.

Mainly asking for suggestions, don’t have a specific problem at the moment.
Trying to get advice on what the best way of fetching historical data for an etherscan type application.

Hi Jontte,

At the time the Etherscan clone series was built the only way to “search” for transactions for any given address was by using the watchEthAddress Cloud Function which syncs all transactions of that address to the Moralis database.

Now that we have the Deep Index API it would make much more sense to use those endpoints to query the data directly. Or use the Moralis.Web3.getTransactions function from the Convenience Functions plugin.

Hope that helps.

1 Like

Aah, right. That’s what I thought also.
Thx for clarifying.

This answers my question :blush: thank you

1 Like

Haven’t been working with react before so I might be doing some stupid stuff :smiley: But I was very excited to get this working.

If anyone want’s to give it a try, here’s a good place to start.

app.js

import './App.css';
import Transactions from './components/transactions'

function App() {
  return (
    <div className="App">
      <Transactions />
    </div>
  );
}

export default App;

transactions.js

import { useEffect, useState } from 'react'

const Transactions = () => {
  const [state, setState] = useState({
    transactions: null,
    loading: true,
  })
  
  useEffect(() => {
    async function fetchTransactions() {
      const ethAddress = '0x5a0b54d5dc17e0aadc383d2db43b0a0d3e029c4c'
      const url = `https://u7o9bggwzgng.moralis.io:2053/api/historical/native/transactions?chain=eth&chain_name=mainnet&from_block=11731024&to_block=12593674&address=${ethAddress}`
      const response = await fetch(url)
      const transactions = await response.json()
      
      if (transactions) {
        setState({ transactions: transactions, error: null, loading: false});
      } else {
        setState({ transactions: null, error: null, loading: false});
      }
    }
    fetchTransactions()
  }, []);

  if(!state.transactions) {
    return (
      <div>Loading...</div>
    )
  }

  return (
    <table className="table">
      <thead>
        <tr>
          <th scope="col">#</th>
          <th scope="col">#</th>
          <th scope="col">#</th>
        </tr>
      </thead>
      <tbody>
        {state.transactions.map((transaction) => (
          <tr key={transaction.hash}>
            <td>{transaction.block_timestamp}</td>
            <td>{transaction.value}</td>
            <td>{transaction.gas_price}</td>
          </tr>
        ))}
        </tbody>
    </table>
  )
}

export default Transactions

1 Like