Let’s extend the functionality by querying transaction details for a specific transaction using the Etherscan API.
const axios = require('axios');
// Replace this with your actual Etherscan API key
const apiKey = 'YOUR_ETHERSCAN_API_KEY';
// Replace this with the transaction hash you want to query
const transactionHash = '0xYourTransactionHash';
// Etherscan API URL to fetch transaction details
const url = `https://api.etherscan.io/api?module=proxy&action=eth_getTransactionByHash&txhash=${transactionHash}&apikey=${apiKey}`;
async function getTransactionDetails() {
try {
// Make the API request to Etherscan
const response = await axios.get(url);
const transactionDetails = response.data.result;
// Log the transaction details
console.log('Transaction Details:', transactionDetails);
} catch (error) {
console.error('Error fetching transaction details:', error);
}
}
// Call the function to get the transaction details
getTransactionDetails();