const { Web3, Web3PluginBase } = require("web3");
const NODE_URL = "CHAINSTACK_NODE_URL";
const web3 = new Web3(NODE_URL);
// Define the TraceBlockPlugin class with only trace_get
class TraceBlockPlugin extends Web3PluginBase {
pluginNamespace = 'trace';
// trace_get method
async traceGet(txHash, transactionPositions) {
return this.requestManager.send({
method: 'trace_get',
params: [txHash, transactionPositions],
});
}
}
// Register the plugin
web3.registerPlugin(new TraceBlockPlugin());
// Function to use traceGet
async function traceGet(txHash, transactionPositions) {
const result = await web3.trace.traceGet(txHash, transactionPositions);
console.log(result);
}
// Example usage of traceGet
const txHash = '0xa2b1e35f59d184da1996b37803ed2e8e81057be7d07a93af48a410fd9338d616'; // Replace with actual block hash
const transactionPositions = ['0x1']; // Replace with actual transaction indices in the block
traceGet(txHash, transactionPositions);