Havenât been working with react before so I might be doing some stupid stuff 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