Improve troubleshooting and smart contract monitoring with advanced analytics

Gain comprehensive insights into smart contract executions, troubleshoot transaction failures, optimize performance, and track specific data.

Improve troubleshooting and smart contract monitoring with advanced analytics

Gain comprehensive insights into smart contract executions, troubleshoot transaction failures, optimize performance, and track specific data.

The Trace API is a set of JSON RPC methods that help Infura users understand how smart contracts and transactions are executed on the Ethereum blockchain. By using the Trace API, developers can access additional information about transactions that are not directly recorded on the blockchain.

This unlocks opportunities to improve DevOps as it enables developers to debug, analyze, and perform specific tasks and functions related to smart contracts optimization, security and analysis.

The Trace API provides a  comprehensive set of methods that allow developers to examine and extract detailed information about transactions, blocks, and contract interactions in Ethereum.

What problem does Trace API solve?

The Trace API solves the problem of limited visibility and understanding of smart contract executions on Ethereum. With the ability to trace transactions, developers can precisely examine the actions executed by the Ethereum Virtual Machine (EVM) during specific transactions or sets of transactions.

Ethereum transactions involve value transfers and contract executions, with the latter being complex interactions that can be challenging to unravel. While transaction receipts provide a basic status code, they lack detailed information about contract execution, making it difficult to determine the specific actions taken, data modifications, and affected addresses.

EVM tracing through the Trace API addresses this problem by enabling developers to gain comprehensive insights into contract executions, allowing for better debugging, analysis, and understanding of smart contracts on the Ethereum network.

How to Access the Infura Trace API

To use the Infura Trace API, follow these simple steps:

  1. Sign up for an Infura account and upgrade to any of the paid plans.
  2. Once you are on a non-free plan, create a web3 API project.
  3. Access your newly created API key, which you will need to make API calls.
  4. Use the provided endpoint along with your API key to access the Trace API methods.

Infura currently supports the following Trace API endpoints on the Ethereum mainnet, as well as the Goerli and Sapolia testnets:

  1. trace_call: Executes a specific call and provides various possible traces for it.
  2. trace_callMany: Executes multiple transactions in a single request.
  3. trace_block: Retrieves the traces executed within a specific block.
  4. trace_transaction: Retrieves all traces associated with a given transaction using the transaction hash.
  5. trace_filter: Retrieves traces that match a specified filter.

Use Case 1: Troubleshoot Transaction Failures and Update Users

When you use the trace_transaction method, it returns a response that can be further analyzed to gain more insight into why a transaction failed. This can be useful for dapp developers as you can now relay this information to your users, prompting them to take the necessary actions.

For example, let's use the Infura trace_transaction method to get the trace tree for this transaction.

Request Code:

curl --location 'https://mainnet.infura.io/v3/<INFURA API KEY> \
--header 'Content-Type: text/plain' \
--data '{
  "id": 1,
  "method": "trace_transaction",
  "jsonrpc": "2.0",
  "params": [
    "0xeb852958eeb1d026b10c6ad3c995520364b83929e1e0908801194f5b680d54ea"
  ]
}'

Response Payload:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": [
    {
      "action": {
        "callType": "call",
        "from": "0xeecc9674d3600e3feb1b01b9ff7c72ac2e1c560f",
        "gas": "0x1a0c8",
        "input": "0xe2bbb158000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000037b1d9c38a24b27c",
        "to": "0xfb063b1ae6471e6795d6ad1fc7f47c1cab1f3422",
        "value": "0x0"
      },
      "blockHash": "0x89b3ee89b30133dfd67888bf0baeea58b8a52b1beb983efcc7aa771a3fd489af",
      "blockNumber": 17370663,
      "error": "out of gas",
      "result": null,
      "subtraces": 4,
      "traceAddress": [],
      "transactionHash": "0xeb852958eeb1d026b10c6ad3c995520364b83929e1e0908801194f5b680d54ea",
      "transactionPosition": 110,
      "type": "call"
    }
  ]
  ...
}

By analyzing the response payload, which includes an error field that says “out of gas”, both the developer and the dApp user gain valuable information about why this transaction failed.

Use Case 2: Troubleshoot Performance Issues with Advanced Analytics

Gaining insight into the number of additional contract calls made before a transaction completes enhances your ability to troubleshoot and optimize for improved performance. Consider an instance where a user invokes a contract that, in turn, invokes another. Merely examining the transaction receipt offers no easy way for a developer to know how many additional smart contracts are invoked under the hood.

Fortunately, the Trace API comes to the rescue by offering a tree view of the transaction trace. This allows a thorough analysis of smart contract performance by observing the number of actions required for a transaction to process, providing valuable data to fine-tune your contract's performance.

Request code:

curl --location 'https://mainnet.infura.io/v3/<INFURA API KEY> \
--header 'Content-Type: text/plain' \
--data '{
  "id": 1,
  "method": "trace_transaction",
  "jsonrpc": "2.0",
  "params": [
    "0x923405094e26b9a616aa7c2b757b5c04c1d65e523f3375e531abb69fc4c2382c"
  ]
}'

Response Payload:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": [
    {
      "action": {
        "callType": "call",
        "from": "0xe67e43b831a541c5fa40de52ab0afbe311514e64",
        "gas": "0x1b803",
        "input": "0xe1021f44000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000182178faefbc461fd10000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000387e55e5b080b30441e82805224ce50b242efe028df1d63b7953dcc7b654d6d37ea9d16750c58c6c8a528f197120cf5180ac3e21a2baa96393bc40c354991fbe063a754751b6ee8d9f35c34c1f3e44fefe1156661f7356117050bc084636b6f4d",
        "to": "0x264382b200bc1fe51a9b58f704394de172341418",
        "value": "0x0"
      },
      "blockHash": "0x37e08159b7961d2ccf83be3d222a821f6be1c5a593854d4c63d1223ecad73bae",
      "blockNumber": 17370903,
      "result": {
        "gasUsed": "0xbeae",
        "output": "0x000000000000000000000000000000000000000000000905f430b36f66685030"
      },
      "subtraces": 1,
      "traceAddress": [],
      "transactionHash": "0x923405094e26b9a616aa7c2b757b5c04c1d65e523f3375e531abb69fc4c2382c",
      "transactionPosition": 178,
      "type": "call"
    },
    {
      "action": {
        "callType": "call",
        "from": "0x264382b200bc1fe51a9b58f704394de172341418",
        "gas": "0x16a44",
        "input": "0xa9059cbb000000000000000000000000e67e43b831a541c5fa40de52ab0afbe311514e64000000000000000000000000000000000000000000000905f430b36f66685030",
        "to": "0xd6123271f980d966b00ca4fca6c2c021f05e2e73",
        "value": "0x0"
      },
      "blockHash": "0x37e08159b7961d2ccf83be3d222a821f6be1c5a593854d4c63d1223ecad73bae",
      "blockNumber": 17370903,
      "result": {
        "gasUsed": "0x7581",
        "output": "0x0000000000000000000000000000000000000000000000000000000000000001"
      },
      "subtraces": 0,
      "traceAddress": [
        0
      ],
      "transactionHash": "0x923405094e26b9a616aa7c2b757b5c04c1d65e523f3375e531abb69fc4c2382c",
      "transactionPosition": 178,
      "type": "call"
    }
  ]
}

When we look at the response details, we see two parts in the results section. Each part stands for a step taken to finish the initial transaction. If we look closer at the 'subtraces' part of the first step, we see the number '1'. This implies the existence of an additional action or child trace associated with that particular transaction.

Use Case 3: Monitor  specific addresses and smart contracts to Improve your DevOps

Using the trace_filter method, you can capture specific events or smart contract interactions on the Ethereum network. By specifying filters like fromAddress, toAddress, fromBlock, and toBlock, you can retrieve a filtered trace of transactions and events that match your filter.

Request Code:

curl --location 'https://mainnet.infura.io/v3/<INFURA API KEY> \
--header 'Content-Type: text/plain' \
--data '{
  "id": 1,
  "method": "trace_filter",
  "jsonrpc": "2.0",
  "params": [
    {
      "toBlock": "0xccb943",
      "fromBlock": "0xccb943",
      "fromAddress": [
        "0xEdC763b3e418cD14767b3Be02b667619a6374076"
      ],
      "toAddress": [
        "0x7ff4169a6b5122b664c51c95727d87750ec07c80"
      ]
    }
  ]
}'

Response Code:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": [
    {
      "action": {
        "callType": "call",
        "from": "0xedc763b3e418cd14767b3be02b667619a6374076",
        "gas": "0x8462",
        "input": "0x095ea7b30000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
        "to": "0x7ff4169a6b5122b664c51c95727d87750ec07c84",
        "value": "0x0"
      },
      "blockHash": "0x351e7c06ec010c8f7e7358eb580238dd23e1e129be96822aa93ebb6da08558e6",
      "blockNumber": 13416771,
      "result": {
        "gasUsed": "0x6009",
        "output": "0x0000000000000000000000000000000000000000000000000000000000000001"
      },
      "subtraces": 0,
      "traceAddress": [],
      "transactionHash": "0x054bbb9fbb855bf23f755e548c7409f45fc5eff8a824b2ad06380bc038d7b049",
      "transactionPosition": 54,
      "type": "call"
    }
  ]
}

Streamline DevOps and Keep Building

The Trace API empowers Ethereum developers with advanced analytics capabilities, allowing them to troubleshoot transaction failures, optimize smart contract performance, and track specific data.

By leveraging the Trace API, developers can enhance their development processes, ensure better security, and provide a superior user experience for their dapps.​​

Access to the Trace API is available to paid customers only. To start utilizing this feature, simply create an Infura account and proceed to upgrade your account. This will enable you to begin using the Trace API.