EVM API Controllers
Purpose
The EVM API Controllers provide a specialized RESTful interface tailored for Ethereum and EVM-compatible blockchains. This subtopic addresses the need for standardized access to blockchain account data, transaction history, transaction broadcasting, gas fee estimation, and token metadata retrieval specifically for EVM-based networks. It solves the challenge of abstracting complex node and indexer interactions into a clean, consistent API that clients can easily consume.
Unlike the broader Unified API Layer that covers multiple blockchain architectures, the EVM API Controllers focus on EVM-specific data structures, RPC methods, and workflows such as handling internal transactions traced via node debug APIs and ERC token standards (ERC20, ERC721, ERC1155). This specialization enables richer and more accurate data representations for Ethereum-like chains.
Functionality
The EVM API Controllers expose a set of key endpoints managing common EVM operations:
Account Information: Retrieves balance, nonce, and a detailed list of token balances (including ERC20 and NFT tokens) for a given address.
Transaction History: Provides paginated transaction history combining on-chain transactions from the Blockbook indexer and internal transactions obtained via external explorer APIs or full node debug tracing.
Transaction Details: Retrieves detailed information on a single transaction by its hash, including internal transactions when available.
Send Transaction: Accepts raw, serialized transaction data and broadcasts it to the blockchain node via JSON-RPC.
Gas Fee Estimation: Interfaces with an internal Gas Oracle to provide current gas fee estimates for different transaction speeds (slow, average, fast).
JSON-RPC Proxy: Supports generic JSON-RPC calls to the underlying Ethereum node, enabling custom queries beyond predefined endpoints.
Token Metadata: Fetches metadata for ERC721 and ERC1155 tokens by querying the token contract's URI methods and resolving associated media URLs.
The controller methods delegate core logic to a dedicated service class that orchestrates data retrieval from the Blockbook indexer, Ethereum node RPC, external explorer APIs, and token contracts. This separation ensures clean API routing while encapsulating complex data processing within the service layer.
Key Workflow Highlights
Transaction History Pagination:
The service combines transactions fetched from Blockbook and internal transactions fetched from explorer APIs or node debug endpoints, merging and filtering them carefully to avoid duplication and ensure completeness across pages.Internal Transaction Retrieval:
Internal transactions (calls and value transfers within contract executions) are obtained either by:Calling
debug_traceTransactionortrace_transactionJSON-RPC methods on a full node, orQuerying an external explorer API for historical data not available via node tracing.
Token Metadata Fetching:
Token URIs are resolved dynamically on-chain using the appropriate ABI call (tokenURIfor ERC721,urifor ERC1155). The returned URI is then fetched over HTTP, handling IPFS and IPNS schemes via a gateway proxy, and decoding base64-encoded JSON metadata if encountered.Gas Estimation and Fees:
Gas estimation uses theviemclient to calleth_estimateGas, while gas fee recommendations are provided by a custom Gas Oracle component tracking recent network gas prices.JSON-RPC Proxying:
Supports forwarding arbitrary JSON-RPC requests or batches to the underlying Ethereum node, enabling custom client queries beyond the standard API.
Integration
This subtopic is a specialized extension of the Unified API Layer, tailored explicitly for EVM-compatible blockchains. It complements sibling API subtopics like the UTXO API Controllers by handling the unique account and transaction models of Ethereum-like chains.
The controllers rely on shared common API interfaces and utilities but implement EVM-specific models, validation, and error handling. They integrate tightly with:
Blockbook Indexer: For base transaction and account data.
Ethereum Node RPC: For broadcasting transactions, tracing internal calls, and performing generic JSON-RPC queries.
Gas Oracle Component: For accurate gas fee estimation.
External Explorer APIs: To supplement internal transaction data not available from nodes, especially for historical transactions.
This layered integration ensures the EVM API Controllers provide the richest possible data and interaction surface for Ethereum-like chains while maintaining consistent API contracts within the broader platform.
Code Snippet Illustrations
Controller Method Example: Getting Account Details
@Get('account/{pubkey}')
async getAccount(@Path() pubkey: string): Promise<Account> {
return EVM.service.getAccount(pubkey)
}
This endpoint delegates to the service's `getAccount` method, which fetches balances and tokens via Blockbook.
Service Method Example: Fetching and Formatting Account Tokens
const tokens = (data.tokens ?? []).reduce<Array<TokenBalance>>((prev, token) => {
if (token.balance && token.contract) {
prev.push({ balance: token.balance, contract: token.contract, decimals: token.decimals ?? 0, ... })
}
token.ids?.forEach(id => { ... }) // ERC721 token handling
token.multiTokenValues?.forEach(multiToken => { ... }) // ERC1155 multi-token handling
return prev
}, [])
The service normalizes multiple token standards into a unified token balance list.
Service Method Example: Sending a Raw Transaction
const request: RPCRequest = {
jsonrpc: '2.0',
id: rpcId(),
method: 'eth_sendRawTransaction',
params: [body.hex],
}
const { data } = await axiosNoRetry.post<RPCResponse>(this.rpcUrl, request, config)
Raw transaction hex is broadcast via JSON-RPC to the node.
Diagram: EVM API Controller Workflow for Transaction History Retrieval
sequenceDiagram
participant Client
participant EVM_API_Controller
participant Service
participant Blockbook
participant Explorer_API
participant Ethereum_Node
Client->>EVM_API_Controller: GET /account/{address}/txs
EVM_API_Controller->>Service: getTxHistory(address, cursor, pageSize, from, to)
Service->>Blockbook: Fetch transactions page
Blockbook-->>Service: Return transactions
Service->>Explorer_API: Fetch internal txs page
Explorer_API-->>Service: Return internal txs
alt Node tracing enabled and recent txs
Service->>Ethereum_Node: debug_traceTransaction / trace_transaction
Ethereum_Node-->>Service: Return internal txs
end
Service->>EVM_API_Controller: Merge & format txs + internal txs + cursor
EVM_API_Controller->>Client: Return paginated TxHistory response
This sequence illustrates how the controller requests transaction history and internal transactions from multiple sources, merges results, and returns a comprehensive response to the client.
This subtopic enriches the Unified API Layer by providing EVM-specific blockchain data access and operations, enabling clients to interact with Ethereum and compatible chains efficiently and with detailed insights into on-chain activity.