debug_traceCall

Runs an eth_call within the context of the given block execution using the final state of parent block as the base.

📘

NOTE

You will not be able to make requests from the browser in the live code example. For context, this has to do with OpenAPI compatibility with JSON-RPC requests. We're working on a solution here but in the meantime, check out the composer tool to make requests from the browser.

Parameters

  1. Object - Transaction object with the following fields:
    • from - string, 20 Bytes - The address the transaction is sent from.
    • to - string, [required] 20 Bytes - The address the transaction is directed to.
    • gas - (optional) Integer of the gas provided for the transaction execution.
    • gasPrice - string, 20 Bytes - Integer formatted as a hex string representing the gas price used for each paid gas.
    • value - string, 20 Bytes - Integer formatted as a hex string representing the value sent with the given transaction.
    • data - string, 20 Bytes - Hash of the method signature and encoded parameters.
  2. String - One of the following options:
    1. block hash
    2. block number (in hex)
    3. block tag (one of the following):
  • pending - A sample next block built by the client on top of latest and containing the set of transactions usually taken from local mempool. Intuitively, you can think of these as blocks that have not been mined yet.
  • latest - The most recent block in the canonical chain observed by the client, this block may be re-orged out of the canonical chain even under healthy/normal conditions.
  • safe - The most recent crypto-economically secure block, cannot be re-orged outside of manual intervention driven by community coordination. Intuitively, this block is “unlikely” to be re-orged. Only available on Ethereum Goerli.
  • finalized - The most recent crypto-economically secure block, that has been accepted by >2/3 of validators. Cannot be re-orged outside of manual intervention driven by community coordination. Intuitively, this block is very unlikely to be re-orged. Only available on Ethereum Goerli.
  • earliest - The lowest numbered block the client has available. Intuitively, you can think of this as the first block created.
  1. Object - tracer
  • tracer - string to specify the type of tracer. Currently supports callTracer and prestateTracer (see below for definitions).
  • tracerConfig - Object to specify configurations for the tracer
    • onlyTopCall - boolean Setting this to true will only trace the main (top-level) call and none of the sub-calls. This avoids extra processing for each call frame if only the top-level call info are required (useful for getting revertReason).

Returns

  • Object - trace object

callTracer

The callTracer tracks all the call frames executed during a transaction, including depth 0. The result will be a nested list of call frames, resembling how EVM works. They form a tree with the top-level call at root and sub-calls as children of the higher levels. Each call frame has the following fields:

fieldtypedescription
typestringCALL or CREATE
fromstringaddress
tostringaddress
valuestringhex-encoded amount of value transfer
gasstringhex-encoded gas provided for call
gasUsedstringhex-encoded gas used during call
inputstringcall data
outputstringreturn data
errorstringerror, if any
revertReasonstringSolidity revert reason, if any
calls[]callframelist of sub-calls

Request

curl --request POST \
     --url https://eth-mainnet.g.alchemy.com/v2/demo \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --data '
{
     "id": 1,
     "jsonrpc": "2.0",
     "method": "debug_traceCall",
     "params": [
          {
               "to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567"
          },
          "finalized",
          {
               "tracer": "callTracer"
          }
     ]
}
'

Response

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "type": "CALL",
    "from": "0x0000000000000000000000000000000000000000",
    "to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
    "value": "0x0",
    "gas": "0x7fffffffffffadf7",
    "gasUsed": "0x0",
    "input": "0x",
    "output": "0x"
  }
}

Things to note about the call tracer:

  • Calls to precompiles are also included in the result
  • In case a frame reverts, the field output will contain the raw return data
  • In case the top level frame reverts, its revertReason field will contain the parsed reason of revert as returned by the Solidity contract
  • Setting the tracerConfig of onlyTopCall to true will only trace the main (top-level) call and none of the sub-calls

prestateTracer

Executing a transaction requires the prior state, including account of sender and recipient, contracts that are called during execution, etc. The prestateTracer replays the tx and tracks every part of state that is touched during that transaction. This is similar to the concept of a stateless witness, the difference being this tracer doesn’t return any cryptographic proof, rather only the trie leaves. The result is an object. The keys are addresses of accounts. The value is an object with the following fields:

fieldtypedescription
balancestringbalance in wei
nonceuint64nonce
codestringhex-encoded bytecode
storagemap[string]stringstorage slots of the contract

Request

curl --request POST \
     --url https://eth-mainnet.g.alchemy.com/v2/demo \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --data '
{
     "id": 1,
     "jsonrpc": "2.0",
     "method": "debug_traceCall",
     "params": [
          {
               "to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567"
          },
          "finalized",
          {
               "tracer": "prestateTracer"
          }
     ]
}
'

Response

{
    "jsonrpc":"2.0",
    "id":1,
    "result":{
        "0x0000000000000000000000000000000000000000":
        {
            "balance":"0x270bc8e8a5208833a09",
            "nonce":0,
            "code":"0x",
            "storage":{}
        },
        "0xd46e8dd67c5d32be8058bb8eb970870f07244567":
        {
            "balance":"0x3944222033a71a",
            "nonce":0,
            "code":"0x",
            "storage":{}
        }
    }
}
Language
URL