trace_get | Fantom

🚧

Dedicated node required

Note that a dedicated node is required to enable the trace and debug APIs on Fantom.

Fantom API method that retrieves a specific trace from a transaction by index. This method is part of the Ethereum client's tracing API, which provides detailed insights into individual transaction steps within the Ethereum Virtual Machine (EVM). It is particularly useful for analyzing transactions with multiple internal calls and operations.

👍

Get your own node endpoint today

Start for free and get your app to production levels immediately. No credit card required.

You can sign up with your GitHub, X, Google, or Microsoft account.

Parameters

  • txHash — the hash of the transaction from which to retrieve the trace.
  • traceIndex — an array of integers specifying the zero-based indices of the traces to retrieve.

Response

  • action — an object that describes the action taken by the transaction:
    • callType — the type of call, such as call, delegatecall, or staticcall.
    • from — the address of the sender who initiated the transaction.
    • gas — the units of gas used by the transaction.
    • input — the data sent with the transaction.
    • to — the recipient of the transaction, if applicable.
    • value — the value transferred in Wei.
  • blockHash — the hash of the block in which the transaction was included.
  • blockNumber — the number of the block in which the transaction was included.
  • result — an object that contains the outcome of the trace:
    • gasUsed — the gas used by the transaction, encoded as hexadecimal.
    • output — the return value of the execution, encoded as a hexadecimal string.
  • subtraces — the number of sub-traces spawned by the trace.
  • traceAddress — an array that indicates the hierarchical position of the trace.
  • transactionHash — the hash of the transaction.
  • transactionPosition — the position of the transaction within the block.
  • type — the type of action taken by the transaction, call or create.

trace_get code examples

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);

const ethers = require('ethers');
const NODE_URL = "CHAINSTACK_NODE_URL";
const provider = new ethers.JsonRpcProvider(NODE_URL);


// Function to use traceGet
async function traceGet(txHash, transactionPositions) {
    const method = 'trace_get';
    const params = [txHash, transactionPositions];

    // Using the provider to send a custom JSON-RPC request
    const result = await provider.send(method, params);
    console.log(result);
}

// Example usage of traceGet
const txHash = '0xa2b1e35f59d184da1996b37803ed2e8e81057be7d07a93af48a410fd9338d616'; // Example block hash
const transactionPositions = ["0x1"]; // Example transaction index

traceGet(txHash, transactionPositions);
from web3 import Web3

# Setup Web3 connection
node_url = "CHAINSTACK_NODE_URL"
web3 = Web3(Web3.HTTPProvider(node_url))

# Function to use trace_get
def trace_get(tx_hash, transaction_positions):
    method = 'trace_get'
    params = [tx_hash, transaction_positions]
    
    # Using the provider to send a custom JSON-RPC request
    result = web3.manager.request_blocking(method, params)
    print(result)

# Example usage of trace_get
tx_hash = '0xa2b1e35f59d184da1996b37803ed2e8e81057be7d07a93af48a410fd9338d616'  # Example block hash
transaction_positions = ['0x1']  # Example transaction index

trace_get(tx_hash, transaction_positions)

Use case

The trace_get method is useful for developers and analysts who must investigate the detailed execution of specific transactions, particularly those involving complex interactions and multiple steps within the EVM. It can help audit smart contract functions, verify transaction logic, and understand the flow of transactions that involve several contract calls.

Try the trace_get RPC method yourself