controller.ts


Overview

The [controller.ts](/projects/291/68853) file implements the REST API controller for the Ethereum Virtual Machine (EVM) blockchain coinstack within a unified multi-blockchain API platform. It exposes a set of HTTP endpoints under the route `/api/v1` that allow clients to:

This controller class, named `EVM`, implements the `BaseAPI` interface (except for gas fee estimation methods) and extends the base `Controller` class from `tsoa` to provide OpenAPI-compliant routing, validation, response types, and example data.

All business logic and blockchain interactions are delegated to a static `Service` instance, separating HTTP concerns from data handling. The controller validates parameters and request bodies, maps HTTP verbs and routes to methods, and defines response schemas including error responses.

This file is a critical part of the Unified API Layer that standardizes blockchain access across different protocols, specialized here for EVM-compatible chains like Ethereum mainnet and testnets.


Class: EVM

Description

`EVM` is a controller class exposing REST endpoints under the `/api/v1` route and tagged as `'v1'`. It implements the core blockchain API for EVM chains by defining HTTP methods decorated with metadata for automatic routing, parameter extraction, validation, and response formatting.

It implements the `BaseAPI` interface (with some omissions) and provides additional endpoints for JSON-RPC proxying and token metadata retrieval.

The controller methods are asynchronous and return promises resolving to typed response models.

Static Properties

Property

Type

Description

`service`

`Service`

Static reference to the EVM `Service` instance handling business logic


Methods

getInfo()

@Get('info/')
async getInfo(): Promise<BaseInfo>

getAccount(pubkey: string)

@Get('account/{pubkey}')
async getAccount(@Path() pubkey: string): Promise<Account>

getTxHistory(pubkey: string, cursor?: string, pageSize?: number, from?: number, to?: number)

@Get('account/{pubkey}/txs')
async getTxHistory(
  @Path() pubkey: string,
  @Query() cursor?: string,
  @Query() pageSize = 10,
  @Query() from?: number,
  @Query() to?: number
): Promise<TxHistory>

getTransaction(txid: string)

@Get('tx/{txid}')
async getTransaction(@Path() txid: string): Promise<Tx>

sendTx(body: SendTxBody)

@Post('send/')
async sendTx(@Body() body: SendTxBody): Promise<string>

doRpcRequest(body: RPCRequest | Array)

@Post('jsonrpc/')
async doRpcRequest(@Body() body: RPCRequest | Array<RPCRequest>): Promise<RPCResponse | Array<RPCResponse>>

getTokenMetadata(contract: string, id: string, type: TokenType)

@Get('/metadata/token')
async getTokenMetadata(
  @Query() contract: string,
  @Query() id: string,
  @Query() type: TokenType
): Promise<TokenMetadata>

Important Implementation Details


Interaction with Other System Components


Usage Summary

Clients interact with this controller over HTTP by sending requests to:


Visual Diagram: Class Structure of EVM Controller

classDiagram
    class EVM {
        <<Controller>>
        +static service: Service
        +getInfo(): Promise<BaseInfo>
        +getAccount(pubkey: string): Promise<Account>
        +getTxHistory(pubkey: string, cursor?: string, pageSize?: number, from?: number, to?: number): Promise<TxHistory>
        +getTransaction(txid: string): Promise<Tx>
        +sendTx(body: SendTxBody): Promise<string>
        +doRpcRequest(body: RPCRequest | RPCRequest[]): Promise<RPCResponse | RPCResponse[]>
        +getTokenMetadata(contract: string, id: string, type: TokenType): Promise<TokenMetadata>
    }
    EVM ..|> Controller
    EVM ..|> BaseAPI
    EVM --> Service : delegates calls

Summary

The [controller.ts](/projects/291/68853) file defines the `EVM` controller class, a REST API interface for EVM-compatible blockchains within a unified multi-blockchain API platform. It exposes endpoints for querying network info, account data, transaction history, transaction details, sending transactions, performing generic JSON-RPC calls, and fetching token metadata. The controller validates inputs, declares response schemas and error cases, and delegates all data processing to a dedicated business logic `Service` class.

This modular design cleanly separates API routing from blockchain interaction logic and integrates with shared API models, error classes, and environment configuration. It is a critical component enabling standardized, extensible blockchain access for Ethereum and compatible chains in the broader Unified API Layer ecosystem.