types.ts


Overview

This file defines TypeScript interfaces used across the project for modeling data structures related to blockchain transaction tracing, debugging, and explorer API responses. These interfaces provide a strongly typed contract for handling complex JSON data returned by blockchain explorers and tracing tools, enabling safer and clearer code when interacting with external APIs or internal data flows.

Key purposes include:


Interfaces and Their Details

1. Cursor

Represents pagination information used to track the position in blockchain data queries, supporting both blockbook and explorer pagination styles.

Property

Type

Optional

Description

`blockHeight`

number

Yes

Optional height of the blockchain block.

`blockbookPage`

number

No

Current page number in blockbook pagination.

`blockbookTxid`

string

Yes

Optional transaction ID in blockbook.

`explorerPage`

number

No

Current page number in explorer pagination.

`explorerTxid`

string

Yes

Optional transaction ID in explorer.

**Usage example:**

const cursor: Cursor = {
  blockbookPage: 1,
  explorerPage: 1,
  blockHeight: 1234567,
};

2. TraceCall

Models a detailed trace of a single call within a transaction, used primarily for deep analysis of Ethereum-like transaction executions.

Property

Type

Description

`action`

Object

Describes the call action details.

`action.callType`

string

Type of call (e.g., "call", "delegatecall").

`action.from`

string

Sender address.

`action.gas`

string

Gas provided for the call.

`action.input`

string

Input data for the call.

`action.to`

string

Target address.

`action.value`

string

Amount of value transferred.

`blockHash`

string

Hash of the block containing the transaction.

`blockNumber`

number

Block number.

`result`

Object

Call result details.

`result.gasUsed`

string

Gas used by the call.

`result.output`

string

Output data from the call.

`subtraces`

number

Number of subtraces/calls within this call.

`traceAddress`

number[]

Array representing call trace path.

`transactionHash`

string

Transaction hash.

`transactionPosition`

number

Position of the transaction in the block.

`type`

string

Type of trace (e.g., "call").

**Usage example:**

const trace: TraceCall = {
  action: {
    callType: "call",
    from: "0xabc...",
    gas: "21000",
    input: "0x",
    to: "0xdef...",
    value: "1000000000000000000",
  },
  blockHash: "0xblockhash...",
  blockNumber: 1234567,
  result: {
    gasUsed: "21000",
    output: "0x",
  },
  subtraces: 0,
  traceAddress: [],
  transactionHash: "0xtxhash...",
  transactionPosition: 1,
  type: "call",
};

3. DebugCallStack

Represents a hierarchical debug call stack used for debugging nested contract calls.

Property

Type

Optional

Description

`type`

string

No

Call type (e.g., "call").

`from`

string

No

Originating address of the call.

`to`

string

No

Target address of the call.

`value`

string

Yes

Amount of value transferred.

`gas`

string

No

Gas provided for the call.

`gasUsed`

string

No

Gas consumed by the call.

`input`

string

No

Input data to the call.

`output`

string

No

Output data from the call.

`calls`

DebugCallStack[]

Yes

Nested calls within this call (recursive).

**Usage example:**

const debugStack: DebugCallStack = {
  type: "call",
  from: "0xabc...",
  to: "0xdef...",
  gas: "100000",
  gasUsed: "21000",
  input: "0xinputdata",
  output: "0xoutputdata",
  calls: [
    {
      type: "call",
      from: "0xdef...",
      to: "0xghi...",
      gas: "80000",
      gasUsed: "20000",
      input: "0xnestedinput",
      output: "0xnestedoutput",
    }
  ]
};

4. ExplorerApiResponse<T>

Generic interface representing the structure of API responses from blockchain explorers.

Property

Type

Description

`status`

string

Status code of the response.

`message`

string

Message describing the response.

`result`

T

Payload of the response, generic type.

**Usage example:**

const response: ExplorerApiResponse<TraceCall[]> = {
  status: "1",
  message: "OK",
  result: [ /* array of TraceCall objects */ ],
};

5. ExplorerInternalTxByHash

Models internal transactions retrieved by transaction hash from a blockchain explorer.

Property

Type

Optional

Description

`index`

number

Yes

Optional index of the internal transaction.

`blockNumber`

string

No

Block number containing the transaction.

`timeStamp`

string

No

Timestamp of the block.

`from`

string

No

Sender address.

`to`

string

No

Recipient address.

`value`

string

No

Value transferred.

`contractAddress`

string

No

Contract address involved, if any.

`input`

string

No

Input data of the transaction.

`type`

string

No

Type of internal transaction.

`gas`

string

No

Gas provided.

`gasUsed`

string

No

Gas consumed.

`isError`

string

No

Error flag ("0" or "1").

`errCode`

string

No

Error code if any.


6. ExplorerInternalTxByAddress

Represents internal transactions retrieved by blockchain address from an explorer API.

Property

Type

Description

`blockNumber`

string

Block number containing the transaction.

`timeStamp`

string

Timestamp of the block.

`hash`

string

Transaction hash.

`from`

string

Sender address.

`to`

string

Recipient address.

`value`

string

Value transferred.

`contractAddress`

string

Contract address involved, if any.

`input`

string

Input data of the transaction.

`type`

string

Type of internal transaction.

`gas`

string

Gas provided.

`gasUsed`

string

Gas consumed.

`traceId`

string

Trace identifier within the transaction.

`isError`

string

Error flag ("0" or "1").

`errCode`

string

Error code if any.


Implementation Details


Interaction with Other Parts of the System


Visual Diagram: Interface Structure Overview

classDiagram
    class Cursor {
        +blockHeight?: number
        +blockbookPage: number
        +blockbookTxid?: string
        +explorerPage: number
        +explorerTxid?: string
    }

    class TraceCall {
        +action: object
        +blockHash: string
        +blockNumber: number
        +result: object
        +subtraces: number
        +traceAddress: number[]
        +transactionHash: string
        +transactionPosition: number
        +type: string
    }

    class DebugCallStack {
        +type: string
        +from: string
        +to: string
        +value?: string
        +gas: string
        +gasUsed: string
        +input: string
        +output: string
        +calls?: DebugCallStack[]
    }

    class ExplorerApiResponse~T~ {
        +status: string
        +message: string
        +result: T
    }

    class ExplorerInternalTxByHash {
        +index?: number
        +blockNumber: string
        +timeStamp: string
        +from: string
        +to: string
        +value: string
        +contractAddress: string
        +input: string
        +type: string
        +gas: string
        +gasUsed: string
        +isError: string
        +errCode: string
    }

    class ExplorerInternalTxByAddress {
        +blockNumber: string
        +timeStamp: string
        +hash: string
        +from: string
        +to: string
        +value: string
        +contractAddress: string
        +input: string
        +type: string
        +gas: string
        +gasUsed: string
        +traceId: string
        +isError: string
        +errCode: string
    }

    DebugCallStack "1" *-- "*" DebugCallStack : calls
    ExplorerApiResponse <|-- ExplorerInternalTxByHash
    ExplorerApiResponse <|-- ExplorerInternalTxByAddress

Summary

The [types.ts](/projects/291/69057) file acts as a centralized type definition hub for blockchain transaction tracing and explorer API data models. It ensures consistent data structures for pagination cursors, trace calls, debug stacks, and explorer internal transactions, facilitating robust integration with blockchain data sources and internal analysis modules. The recursive and generic typing patterns support complex nested data scenarios commonly encountered in smart contract execution tracing and blockchain data exploration.