controller.ts


Overview

`controller.ts` defines a RESTful API controller for interacting with the Solana blockchain. It provides endpoints to retrieve blockchain information, account details, transaction history, transaction details, send transactions, estimate fees, perform JSON-RPC calls, and fetch token metadata. The controller leverages the `helius-sdk` and Solana's web3.js library to interact with the Solana network and an external indexer to query transaction history.

This file acts as a thin API layer exposing Solana blockchain data and transaction functionality to clients while handling validation, error management, and data formatting.


Class: Solana

The `Solana` class implements the [BaseAPI](/projects/291/69264) and `API` interfaces and is decorated with tsoa decorators for routing and API documentation. It defines multiple endpoints under the route prefix `/api/v1`.

Static Properties

Property

Type

Description

`baseFee`

string

A constant base fee value (5000).


Methods


getInfo()

async getInfo(): Promise<BaseInfo>

getAccount(pubkey: string)

async getAccount(pubkey: string): Promise<Account>

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

async getTxHistory(pubkey: string, cursor?: string, pageSize = 10): Promise<TxHistory>

getTransaction(txid: string)

async getTransaction(txid: string): Promise<Tx>

sendTx(body: SendTxBody)

async sendTx(body: SendTxBody): Promise<string>

getPriorityFees()

async getPriorityFees(): Promise<PriorityFees>

estimateFees(body: EstimateFeesBody)

async estimateFees(body: EstimateFeesBody): Promise<string>

doRpcRequest(body: RPCRequest | RPCRequest[])

async doRpcRequest(body: RPCRequest | Array<RPCRequest>): Promise<RPCResponse | Array<RPCResponse>>

getToken(id: string)

async getToken(id: string): Promise<Token>

Important Implementation Details


Interactions with Other Parts of the System


Usage Example Summary

Endpoint

HTTP Method

Description

`/api/v1/info/`

GET

Get coinstack info

`/api/v1/account/{pubkey}`

GET

Get account details by pubkey

`/api/v1/account/{pubkey}/txs`

GET

Get transaction history

`/api/v1/tx/{txid}`

GET

Get transaction details

`/api/v1/send/`

POST

Send raw base64-encoded tx

`/api/v1/fees/priority`

GET

Get priority fee levels

`/api/v1/fees/estimate`

POST

Estimate fees for serialized tx

`/api/v1/jsonrpc/`

POST

JSON-RPC request(s) to node

`/api/v1/token/{id}`

GET

Get token metadata


Mermaid Class Diagram

classDiagram
    class Solana {
        <<API Controller>>
        +static baseFee: string
        +getInfo() Promise~BaseInfo~
        +getAccount(pubkey: string) Promise~Account~
        +getTxHistory(pubkey: string, cursor?: string, pageSize?: number) Promise~TxHistory~
        +getTransaction(txid: string) Promise~Tx~
        +sendTx(body: SendTxBody) Promise~string~
        +getPriorityFees() Promise~PriorityFees~
        +estimateFees(body: EstimateFeesBody) Promise~string~
        +doRpcRequest(body: RPCRequest | Array~RPCRequest~) Promise~RPCResponse | Array~RPCResponse~
        +getToken(id: string) Promise~Token~
    }

Summary

`controller.ts` exposes a comprehensive Solana blockchain API that wraps low-level RPC calls and indexer queries into a user-friendly REST interface. It supports querying account balances and tokens, fetching transaction history and details, sending transactions, estimating fees, and performing raw RPC requests. The use of tsoa ensures well-documented, validated endpoints and strong typing. The file is a crucial bridge between the Solana network and client applications, encapsulating blockchain complexity and enhancing developer usability.