> ## 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.

# arbtrace_replayTransaction | Arbitrum

Arbitrum API method that replays a specific transaction and returns the traces. Developers can use the `arbtrace_replayTransaction` method to gain insight into the behavior of smart contracts, analyze gas usage, and optimize their contracts accordingly.

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

<Warning>
  Blocks older than 22,207,815 were added to the chain before the Nitro migration and cannot be queried with Geth `debug_*` methods. Starting from block 22,207,815, Arbitrum migrated to Nitro which made Geth `debug_*` methods available for newer blocks.

  Use the `arbtrace_replayTransaction` method for calling blocks prior to 22,207,815.
</Warning>

<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

* `hash` — the hash identifying a transaction.
* `array` — an array identifying the type of tracer and its configuration:

  * `trace` — 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.

## Response

* `output` — the data returned as a result of the transaction, encoded in hexadecimal format.
* `stateDiff` — reveals changes to the state resulting from the execution of the given transaction.
* `trace` — the basic trace of specific information.
  * `action` — the operation to be performed on the recipient.
    * `from` — the address initiating the transaction.
    * `callType` — the type of method, such as `call` or `delegatecall`.
    * `gas` — the units of gas supplied by the sender, encoded in hexadecimal format.
    * `input` — the data transmitted along with the transaction, typically used for interaction with smart contracts.
    * `to` — the recipient's address. If it's a contract creation transaction, this field is `null`.
    * `value` — the amount sent with the transaction, encoded as a hexadecimal.
  * `result` — the value of the gas price used, encoded as hexadecimal.
    * `gasUsed` — the total amount of gas used by all the transactions in the block, encoded as hexadecimal.
    * `output` — the return value from the contract call, encoded in hexadecimal. If the `RETURN` method isn't executed, the output will be empty bytes.
  * `subtraces` — a list of contract calls made by the transaction, each represented as a nested `call`frame object.
  * `traceAddress` — a list of addresses where the call was executed, the addresses of the parent calls, and the order of the current sub-call.
  * `type` — the value of the method, such as `call` or `create`.
* `vmTrace` — a comprehensive trace of the virtual machine's state during the execution of a given transaction, including any sub-calls.
* `destroyedContracts` — a list of the smart contract destroyed during the block execution; `null` if no contract was destroyed.

## `arbtrace_replayTransaction` code examples

<CodeGroup>
  ```javascript web3.js theme={"system"}
  const Web3 = require("web3");
  const NODE_URL = "YOUR_CHAINSTACK_ENDPOINT";
  const web3 = new Web3(NODE_URL);

  // Define the arbtrace_replayTransaction custom method
  web3.extend({
      property: 'arbtrace',
      methods: [{
        name: 'replayTransaction',
        call: 'arbtrace_replayTransaction',
        params: 2,
      }],
    });
    
    async function arbtraceReplay() {
      const hash = "0xe8648e3ad982a3d67ef0880d6631343cffff364786994b34e5fa292cfef0e680";
      const traceOptions = ["trace"];
    
      try {
        const result = await web3.arbtrace.replayTransaction(hash, traceOptions);
        console.log(result);
      } catch (error) {
        console.error("Error:", error);
      }
    }
    
    arbtraceReplay();
  ```

  ```javascript ethers.js theme={"system"}
  const ethers = require('ethers');
  const NODE_URL = "YOUR_CHAINSTACK_ENDPOINT";
  const provider = new ethers.JsonRpcProvider(NODE_URL);

  const arbtraceReplayTransaction = async () => {
      const hash = '0xe8648e3ad982a3d67ef0880d6631343cffff364786994b34e5fa292cfef0e680'
      const tracer = 'trace';

      const traces = await provider.send("arbtrace_replayTransaction", [hash, [tracer]]);
      console.log(traces);
  };

  arbtraceReplayTransaction()
  ```

  ```python web3.py theme={"system"}
  from web3 import Web3  
  node_url = "YOUR_CHAINSTACK_ENDPOINT" 
  web3 = Web3.HTTPProvider(node_url)

  transactionHash = "0xe8648e3ad982a3d67ef0880d6631343cffff364786994b34e5fa292cfef0e680";
  traceOptions = ["trace"];

  response = web3.provider.make_request('arbtrace_replayTransaction', [transactionHash, traceOptions])
  print(response)
  ```
</CodeGroup>

## Use case

The `arbtrace_replayTransaction` allows you to replay a specific transaction and analyze its interactions.

Suppose you are a smart contract developer working on a decentralized application that involves multiple contract interactions within a single transaction. During the development process, you encounter unexpected behaviors or errors when executing certain transactions, and you need to understand the root cause.

In such a scenario, you can use the `arbtrace_replayTransaction` method to replay the problematic transaction and retrieve the traces associated with it. By analyzing these traces, you can gain valuable insights into the execution flow and pinpoint the cause of the issue.


## OpenAPI

````yaml /openapi/arbitrum_node_api/debug_and_trace/arbtrace_replayTransaction.json POST /66f812de2a6724a75a51f60dd6f2a154
openapi: 3.0.0
info:
  title: Chainstack Node API
  version: 1.0.4
  description: >-
    This is an API for interacting with a Chainstack node using the
    arbtrace_replayTransaction method.
servers:
  - url: https://nd-954-882-037.p2pify.com
security: []
paths:
  /66f812de2a6724a75a51f60dd6f2a154:
    post:
      tags:
        - upload
      summary: arbtrace_replayTransaction
      operationId: arbtraceReplayTransaction
      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: arbtrace_replayTransaction
                params:
                  type: array
                  items:
                    anyOf:
                      - type: string
                        title: Transaction Hash
                      - type: array
                        items:
                          type: string
                        title: Options Array
                  default:
                    - >-
                      0xe8648e3ad982a3d67ef0880d6631343cffff364786994b34e5fa292cfef0e680
                    - - trace
      responses:
        '200':
          description: The replayed transaction's trace.
          content:
            application/json:
              schema:
                type: object
                properties:
                  jsonrpc:
                    type: string
                  id:
                    type: integer
                  result:
                    type: object

````