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();
- Replace
'YOUR_ETHERSCAN_API_KEY'
with your actual Etherscan API key. - Replace
'0xYourTransactionHash'
with the transaction hash you want to query. - This script uses the
eth_getTransactionByHash
endpoint to fetch transaction details, such as gas price, block number, and sender/receiver addresses.