> ## Documentation Index
> Fetch the complete documentation index at: https://docs.chainstack.com/llms.txt
> Use this file to discover all available pages before exploring further.

# debug_traceCall | Ethereum

Ethereum API method that traces the execution of [eth\_call](/reference/ethereum-ethcall) within the context of a specific block's execution. This method uses the final state of the parent block as its base and allows developers to trace the execution of a particular call.

<Note>
  Learn how to [deploy a node](/docs/debug-and-trace-apis#ethereum) with the debug and trace API methods enabled.
</Note>

<Check>
  **Get your own node endpoint today**

  [Start for free](https://console.chainstack.com/) and get your app to production levels immediately. No credit card required.

  You can sign up with your GitHub, X, Google, or Microsoft account.
</Check>

## Parameters

* `object` — the transaction call object:

  * `from` — (optional) the string of the address used to send the transaction.
  * `to` — the string of the address to which the transaction is directed, a wallet, or a smart contract.
  * `gas` — (optional) the maximum amount of gas that can be used by the transaction.
  * `gasprice` — (optional) the amount of gas price the sender is willing to pay for each gas unit in [Wei](https://ethereum.org/en/developers/docs/intro-to-ether/#denominations).
  * `value` — (optional) the value sent with this transaction, encoded as hexadecimal.
  * `data` — (optional) additional data to be sent with the call, usually used to invoke functions from smart contracts as a string of the hash of the method signature and encoded parameters; see the [Ethereum Contract ABI](https://solidity.readthedocs.io/en/latest/abi-spec.html).
* `quantity or tag` — the integer of a block encoded as hexadecimal or the string with:

  * `latest` — the most recent block in the blockchain and the current state of the blockchain at the most recent block. A chain reorganization is to be expected.
  * `safe`—the block that received justification from the beacon chain. Although this block could be involved in a chain reorganization, it would necessitate either a coordinated attack by the majority of validators or severe propagation latency.
  * `finalized`—the block accepted as canonical by more than 2/3 of the validators. A chain reorganization is extremely unlikely, requiring burning at least 1/3 of the staked amount.
  * `earliest` — the earliest available or genesis block.
  * `pending`—the pending state and transactions block. This is the current state of transactions that have been broadcast to the network but have not yet been included in a block.

<Note>
  See the [default block parameter](https://ethereum.org/en/developers/docs/apis/json-rpc/#default-block).
</Note>

* `object` — (optional) an object identifying the type of tracer and its configuration:

  * `4byteTracer` — tracer that captures the function signatures and call data sizes for all functions executed during a transaction, creating a map that links each selector and size combination to the number of times it occurred. This provides valuable information about the frequency and usage of each function within the transaction.
  * `callTracer` — tracer that captures information on all call frames executed during a transaction. The resulting nested list of call frames is organized into a tree structure that reflects the way the Ethereum Virtual Machine works and can be used for debugging and analysis purposes.
  * `prestateTracer` — tracer with two modes: `prestate` and `diff`, where the former returns the accounts needed to execute a transaction, and the latter returns the differences between the pre and post-states of the transaction. The tracer operates by re-executing the transaction and tracking every state change made, resulting in an object with the account addresses as keys and the corresponding trie leaves as values.

<Note>
  Find a complete [list of available built-in tracers](/reference/ethereum-debug-trace-rpc-methods#pre-built-javascript-based-tracers) in the debug and trace overview.
</Note>

You can also use additional configuration parameters. The following settings are available:

* `disableStorage` — when enabled, it prevents tracing of storage changes made by the transaction being analyzed, which can reduce the resource requirements of the analysis. By default, `debug_traceTransaction` traces both memory and storage changes, but storage tracing can be particularly resource-intensive, especially for large transactions.
* `disableStack` — when enabled, it skips tracing of [stack](https://en.wikipedia.org/wiki/Stack_\(abstract_data_type\)) changes made by the transaction being analyzed. This can be helpful in optimizing performance and resource usage, especially when analyzing complex transactions, but may result in reduced analysis accuracy that should be considered.
* `enableMemory` — when `false`, it prevents tracing of memory changes made by the transaction being analyzed, which can reduce the resource requirements of the analysis. This can be helpful in optimizing performance and resource usage, especially when analyzing complex transactions, but may result in reduced analysis accuracy that should be considered.

<Warning>
  Note that on an Erigon client, this setting is the opposite and is named `disableMemory`.
</Warning>

* `enableReturnData` — when `false`, it prevents the method from tracing the return data produced by the transaction being analyzed. The return data tracing can be particularly resource-intensive, requiring a significant amount of time and processing power to complete.

<Warning>
  Note that on an Erigon client, this setting is the opposite and is named `disableReturnData`.
</Warning>

* `timeout` — setting that allows developers to customize the method's timeout period for JavaScript-based tracing calls. The default timeout is `5s`, and you can find the values formats in the [Go documentation](https://pkg.go.dev/time#ParseDuration).

<Note>
  It's worth noting that when using one of the three built-in tracers in Ethereum clients, the `enableMemory`, `disableStorage`, `disableStack`, and `enableReturnData`settings will not have any effect.

  When no built-in tracer is selected, the response defaults to the [Struct/opcode logger](https://geth.ethereum.org/docs/developers/evm-tracing/built-in-tracers#structopcode-logger).
</Note>

## Response types

### `4byteTracer` response

* `object` — the `4byteTracer` traces object:
  * `result` — a map of the function signature, the call data size, and how many times the function was called.

### `callTracer` response

* `object` — the `callTracer` traces object:
  * `from` — the address of the sender who initiated the transaction.
  * `gas` — the units of gas included in the transaction by the sender.
  * `gasused` — the total used gas by the call, encoded as hexadecimal.
  * `to` — the address of the recipient of the transaction if it was a transaction to an address. For contract creation transactions, this field is `null`.
  * `input` — the optional input data sent with the transaction., usually used to interact with smart contracts.
  * `output` — the return value of the call, encoded as a hexadecimal string.
  * `error` — an error message in case the execution failed.
  * `revertReason` — the reason why the transaction was reverted, returned by the smart contract, if any.
  * `calls` — a list of sub-calls made by the contract during the call, each represented as a nested call frame object.

### `prestateTracer` response

* `object` — the `prestateTracer` traces object:
  * `smart contract address` — the address of the smart contract associated with the result.
    * `balance` — the balance of the contract, expressed in Wei and encoded as a hexadecimal string.
    * `code` — the bytecode of the contract, encoded as a hexadecimal string.
    * `nonce` — the nonce of the account associated with the contract, represented as an unsigned integer.
    * `storage` — a map of key-value pairs representing the storage slots of the contract. The keys and values are both encoded as hexadecimal strings.

### `Struct/opcode logger` response

* `object` — the `Struct/opcode logger` traces object:
  * `pc` — the current program counter of the transaction, which represents the location of the current opcode being executed. A register that keeps track of the address of the next instruction to be executed in a program.
  * `op` — the current [opcode](https://ethereum.org/en/developers/docs/evm/opcodes/) being executed, such as PUSH1, ADD, or SWAP1. A code that represents a specific operation or instruction that a computer or processor can understand and execute.
  * `gas` — the amount of gas remaining in the transaction at the current step of execution.
  * `gasCost` — the amount of gas consumed by the current opcode being executed.
  * `depth` — the current depth of the call stack for the transaction, reflecting the number of active frames representing nested function calls.
  * `stack` — the contents of the EVM stack at the current step of the transaction's execution. The stack is a data structure used by the EVM to manage and manipulate data during the execution of opcodes
  * `memory` — the contents of the memory at the current step of execution. A temporary data storage location that is available to smart contracts during execution.

## `debug_traceCall` code examples

<Note>
  Learn more about the `ChainstackProvider` in `ethers.js`: [ethers ChainstackProvider Documentation](/reference/ethersjs-chainstackprovider).
</Note>

<CodeGroup>
  ```javascript ethers.js theme={"system"}
  const ethers = require("ethers");

  // Create a ChainstackProvider instance for Ethereum mainnet
  const chainstack = new ethers.ChainstackProvider("mainnet");

  const traceCall = async () => {
    const call = {
      from: "0xe7e8569267c4a3278be75a2d86fd1a9e0a6818d8",
      to: "0xc2edad668740f1aa35e4d8f227fb8e17dca888cd",
      gas: "0x1E9EF",
      gasPrice: "0x72AC5BA54E",
      data: "0x441a3e70000000000000000000000000000000000000000000000000000000000000010300000000000000000000000000000000000000000000000000c6c3eca729cb9e",
    };

    const block = "latest";

    // Specify the type of tracer: 4byteTracer, callTracer, or prestateTracer. Leave empty {} for Struct/opcode logger.
    const tracer = {};
    const traces = await chainstack.send("debug_traceCall", [
      call,
      block,
      tracer,
    ]);
    console.log(traces);
  };

  traceCall();
  ```

  ```javascript web3.js theme={"system"}
  const { Web3, Web3PluginBase } = require("web3");
  const NODE_URL = "CHAINSTACK_NODE_URL";
  const web3 = new Web3(NODE_URL);

  // Define the TraceBlockPlugin class
  class TraceBlockPlugin extends Web3PluginBase {
      pluginNamespace = 'trace';

      async traceCall(call, txHash, tracer) {
          return this.requestManager.send({
              method: 'debug_traceCall',
              params: [call, txHash, tracer],
          });
      }
  }

  // Register the plugin
  web3.registerPlugin(new TraceBlockPlugin());

  async function traceCall() {

      const call = {
        from: '0xae2Fc483527B8EF99EB5D9B44875F005ba1FaE13',
        to: '0xc2edad668740f1aa35e4d8f227fb8e17dca888cd',
        gas: '0x1E9EF',
        gasPrice: '0x72AC5BA54E',
        data: '0x441a3e70000000000000000000000000000000000000000000000000000000000000010300000000000000000000000000000000000000000000000000c6c3eca729cb9e'
      }
    
      const block = 'latest'
    
      // Specify the type of tracer: 4byteTracer, callTracer, or prestateTracer. Leave empty {} for Struct/opcode logger.
      const tracer = {'tracer' : '4byteTracer'};
      const result = await web3.trace.traceCall(call, block, tracer);
      console.log(result);
    }
    
    traceCall();
  ```

  ```python web3.py theme={"system"}
  from web3 import Web3  
  node_url = "CHAINSTACK_NODE_URL" 
  web3 = Web3.HTTPProvider(node_url)

  call = {
      'from': '0xe7e8569267c4a3278be75a2d86fd1a9e0a6818d8',
      'to': '0xc2edad668740f1aa35e4d8f227fb8e17dca888cd',
      'gas': '0x1E9EF',
      'gasPrice': '0x72AC5BA54E',
      'data': '0x441a3e70000000000000000000000000000000000000000000000000000000000000010300000000000000000000000000000000000000000000000000c6c3eca729cb9e'
    }

  block = 'latest'

  # Specify the type of tracer: 4byteTracer, callTracer, or prestateTracer. Leave empty {} for Struct/opcode logger.
  tracer = { "tracer": 'prestateTracer' }
  tx_traces = web3.provider.make_request('debug_traceCall', [call, block, tracer])
  print(tx_traces)
  ```
</CodeGroup>

## Use case

A practical use case for the `debug_traceCall` method is to inspect the internal transactions that happened during a smart contract call. For example, a developer can examine a past transaction using the `callTracer` tracer where an account used a proxy smart contract to deploy a new instance using the `CREATE2` method.

<Note>
  Read [Deploying a deterministic smart contract on Ethereum](https://chainstack.com/deploying-a-deterministic-contract-on-ethereum/) to learn more about the `CREATE2` method and how to deploy a smart contract to a predetermined address.
</Note>

The following code is an implementation of the logic to inspect internal transactions using web3.js:

```javascript index.js theme={"system"}
const { Web3, Web3PluginBase } = require("web3");
const NODE_URL = "CHAINSTACK_NODE_URL";
const web3 = new Web3(NODE_URL);

// Define the TraceBlockPlugin class
class TraceBlockPlugin extends Web3PluginBase {
    pluginNamespace = 'trace';

    async traceCall(call, txHash, tracer) {
        return this.requestManager.send({
            method: 'debug_traceCall',
            params: [call, txHash, tracer],
        });
    }
}

// Register the plugin
web3.registerPlugin(new TraceBlockPlugin());

async function traceCall(call, block) {
    try {
      // Specify the type of tracer: 4byteTracer, callTracer, or prestateTracer.
      // Leave empty {} for Struct/opcode logger.
      const tracer = { tracer: 'callTracer' };
  
      // Trace the call
      const result = await web3.trace.traceCall(call, block, tracer);
      const calls = result.calls;
  
      console.log(`===== Internal Calls =====`);
  
      // Extract and display the desired properties from each result object using a loop
      for (const callObj of calls) {
        const from = callObj.from;
        const to = callObj.to;
        const internalCalls = callObj.calls;
  
        console.log(`From: ${from}`);
        console.log(`To: ${to}`);
  
        for (const internalCall of internalCalls) {
          const type = internalCall.type;
          console.log(`Type: ${type}\n`);
        }
      }
    } catch (error) {
      console.error(`Error while tracing call: ${error}`);
    }
  }
  
  async function main() {
    try {
      const call = {
        from: '0xa7fb5ca286fc3fd67525629048a4de3ba24cba2e',
        to: '0xc77ad0a71008d7094a62cfbd250a2eb2afdf2776',
        gas: '0x186A0',
        gasPrice: '0xEE6B28000',
        data: '0xf3fef3a3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000617c2'
      };
  
      // Define the block number or block tag to trace
      const block = '0x100A74D';
  
      await traceCall(call, block);
    } catch (error) {
      console.error(`Error while executing main: ${error}`);
    }
  }
  
  main();
```

The `traceCall` function is an asynchronous function that takes two parameters: `call` and `block`. The `call` parameter is an object that contains the details of the call that needs to be traced. In this case, those are the details of a [transaction that deployed a smart contract instance using the CREATE2 method](https://etherscan.io/tx/0x424583a1739057c8cf418d39ed314548dfa2fe3a8c77f22bd4efdeaddc031bf1#internal) on the Ethereum blockchain. The block parameter is the block number or block tag to trace.

The function first creates a tracer object that specifies the type of tracer to be used. In this case, it's set to `callTracer`, which means that the function will trace all the internal calls made by the smart contract during the execution of the specified call.

The function then calls the `web3.debug.traceCall` function (which was previously created using `web3.extend`) with the `call`, `block`, and `tracer` parameters. This function returns an object that contains information about the internal calls made by the smart contract during the execution of the specified call.

The function then loops through the array of calls in the `result` object and extracts the `from`, `to`, and `calls` properties of each call object. The `from` property is the address of the sender of the call, the `to` property is the address of the smart contract being called, and the `calls` property is an array of objects that represent the internal calls made by the smart contract during the execution of the call.

The function then loops through the `internalCalls` array of each call object and extracts the `type property` of each `internalCall` object. The `type` property represents the type of the internal call, such as a contract creation or an external function call.

Finally, the function logs the extracted information to the console.

The main function is also an asynchronous function that simply calls the `traceCall` function with the appropriate parameters. It also wraps the function call in a try-catch block to handle any errors that might occur during execution.


## OpenAPI

````yaml /openapi/ethereum_node_api/debug_and_trace/debug_traceCall.json POST /0a9d79d93fb2f4a4b1e04695da2b77a7
openapi: 3.0.0
info:
  title: Ethereum Node API
  version: 1.0.0
  description: This is an API for interacting with an Ethereum node.
servers:
  - url: https://nd-422-757-666.p2pify.com
security: []
paths:
  /0a9d79d93fb2f4a4b1e04695da2b77a7:
    post:
      tags:
        - Ethereum Operations
      summary: debug_traceCall
      operationId: traceCall
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                id:
                  type: integer
                  default: 1
                jsonrpc:
                  type: string
                  default: '2.0'
                method:
                  type: string
                  default: debug_traceCall
                params:
                  type: array
                  items:
                    anyOf:
                      - type: object
                        properties:
                          from:
                            type: string
                            default: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'
                          to:
                            type: string
                            default: '0x0000000000a39bb272e79075ade125fd351887ac'
                          gas:
                            type: string
                            default: '0x1E9EF'
                          gasPrice:
                            type: string
                            default: '0xBD32B2ABC'
                          data:
                            type: string
                            default: '0xd0e30db0'
                      - type: string
                        default: latest
                      - type: object
                        properties:
                          tracer:
                            type: string
                            default: callTracer
                  default:
                    - from: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'
                      to: '0x0000000000a39bb272e79075ade125fd351887ac'
                      gas: '0x1E9EF'
                      gasPrice: '0xBD32B2ABC'
                      data: '0xd0e30db0'
                    - latest
                    - tracer: callTracer
      responses:
        '200':
          description: The result of the debug trace call
          content:
            application/json:
              schema:
                type: object
                properties:
                  jsonrpc:
                    type: string
                  id:
                    type: integer
                  result:
                    type: object

````