const ethers = require('ethers');
const NODE_URL = "CHAINSTACK_NODE_URL";
const provider = new ethers.JsonRpcProvider(NODE_URL);
const traceBlock = async (blockNumber) => {
const traces = await provider.send("trace_block", [blockNumber]);
console.log(`Block has ${traces.length} traces`);
// Group traces by transaction
const txTraces = {};
for (const trace of traces) {
const txHash = trace.transactionHash;
if (!txTraces[txHash]) {
txTraces[txHash] = [];
}
txTraces[txHash].push(trace);
}
console.log(`Across ${Object.keys(txTraces).length} transactions`);
for (const [txHash, txTrace] of Object.entries(txTraces)) {
console.log(`\nTx: ${txHash}`);
for (const trace of txTrace) {
const indent = " ".repeat(trace.traceAddress.length);
console.log(`${indent}${trace.action.callType}: ${trace.action.from} -> ${trace.action.to}`);
}
}
};
traceBlock("latest");