NodeRpcClient

interface NodeRpcClient

Client for Midnight node JSON-RPC API.

Submits transactions to the Midnight blockchain via the node's RPC interface.

JSON-RPC 2.0 Protocol:

  • Endpoint: HTTP POST to node RPC (default: http://localhost:9944)

  • Method: author_submitExtrinsic (standard Substrate RPC)

  • Params: Hex-encoded serialized transaction (SCALE codec)

  • Response: Transaction hash (32 bytes hex)

Transaction Lifecycle (with WebSocket):

1. Submit via WebSocket → Get subscription
2. Receive status events: ready → broadcast → inBlock → finalized
3. Return when finalized (typically 6-12 seconds)

Error Handling:

  • Network errors: Retry with exponential backoff

  • Server errors (5xx): Retry with backoff

  • Client errors (4xx): Don't retry

  • Transaction rejected: Don't retry (fix transaction)

See also

for implementation details

Inheritors

Types

Link copied to clipboard

Stages during transaction submission, for progress UX.

Functions

Link copied to clipboard
abstract fun close()

Close the client and release resources.

Link copied to clipboard
abstract suspend fun getFinalizedHead(): String

Get the hash of the latest finalized block.

Link copied to clipboard
abstract suspend fun isHealthy(): Boolean

Check if node is healthy and reachable.

Link copied to clipboard
abstract suspend fun submitAndWaitForFinalization(serializedTxHex: String, timeoutMs: Long, onStage: suspend (NodeRpcClient.SubmissionStage) -> Unit? = null): TransactionFinalizationResult

Submit a transaction and wait for it to be finalized on-chain.

Link copied to clipboard
abstract suspend fun submitTransaction(serializedTxHex: String): String

Submit a serialized transaction to the Midnight node (fire-and-forget).