I am facing challenges when I try to fetch the transaction amount from Arbiscan (using Arbiscan API).

I want to fetch the transaction amount of my latest transaction using Node.js. The following Javascript code fetches the latest transaction hash:

const API_KEY = 'API_KEY ';

async function fetchFromAPI(url) {
  try {
    const response = await fetch(url);
    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    return await response.json();
  } catch (error) {
    console.error('API Fetch Error:', error);
    return null; 

async function getLatestTransactionHash(apiKey, walletAddress) {
  const url = `https://api.arbiscan.io/api?module=account&action=txlist&address=${walletAddress}&startblock=0&endblock=99999999&page=1&offset=1&sort=desc&apikey=${apiKey}`;
  const data = await fetchFromAPI(url);
  return data && data.result && data.result.length > 0 ? data.result[0].hash : null;

async function main() {
  const latestTransactionHash = await getLatestTransactionHash(API_KEY, WALLET_ADDRESS);
  if (latestTransactionHash) {
    console.log('Latest Transaction Hash:', latestTransactionHash);
  } else {
    console.log('No transactions found or error fetching transactions.');


How can I modify the code to fetch the transaction amount of the latest transaction hash?

Thank you in advance!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.