Skip to content

feat(grpc): Node-side @sentrix/chain/grpc client + bundled .proto#16

Merged
satyakwok merged 1 commit into
mainfrom
feat/grpc-node-client
May 10, 2026
Merged

feat(grpc): Node-side @sentrix/chain/grpc client + bundled .proto#16
satyakwok merged 1 commit into
mainfrom
feat/grpc-node-client

Conversation

@satyakwok
Copy link
Copy Markdown
Member

Summary

Completes the SDK surface coverage. Existing doors: `evm` (viem), `native` (REST), `bft` (WebSocket subs), `wallet` (signing). New: `grpc` — typed wrapper around the chain's `sentrix.v1.Sentrix` service over `@grpc/grpc-js`. Node-only; browser consumers use the gRPC-Web transport in sentrix-explorer-v2 or wire `grpc-web` npm directly.

Why a thin wrapper

  1. Bundle the `.proto` with the npm package — version-locked to the SDK so a chain proto bump can't silently mismatch your client.
  2. Centralise the endpoint URL (`grpc.sentrixchain.com:443` / `grpc-testnet.sentrixchain.com:443`) via the same network spec the rest of the SDK uses.
  3. Hide the `proto-loader` → service-stub plumbing so consumers don't reach into `@grpc/grpc-js` internals.

Available calls (chain v0.4+)

Method Returns
`getLatestBlock()` / `getBlockByHeight(h)` `Block`
`getBalance(address)` `Account` (20-byte hex or Buffer accepted)
`getValidatorSet({ atHeight? })` `ValidatorSet` (full active set + flags)
`getSupply({ atHeight? })` `Supply` (minted/burned/circ)
`getMempool({ limit })` `Mempool` (size + headers)
`streamEvents([filters])` server-stream of `ChainEvent`

Older chain hosts (v0.2 / v0.3) return `Status::unimplemented` for the newer methods; the SDK forwards the error verbatim so callers can fall back to JSON-RPC / REST.

Usage

```ts
import { GrpcClient } from "@sentrix/chain/grpc";

const c = new GrpcClient("mainnet");
const block = await c.getLatestBlock();
const bal = await c.getBalance("0x4693b113e523A196d9579333c4ab8358e2656553");

// Server-stream — drain with for-await
for await (const ev of c.streamEvents([])) {
console.log(ev);
}

c.close();
```

Build flow

`tsc` compiles src → dist; an inline `mkdir -p dist/grpc-proto && cp` step ships the bundled `.proto` next to the compiled JS so `proto-loader`'s runtime path resolution works for both `pnpm dev` (src/) and the published package (dist/).

Verification

End-to-end against live `grpc.sentrixchain.com:443` — `getLatestBlock()` returns block 1678214 in ~250 ms.

Out of scope

  • Browser gRPC-Web wrapper — sentrix-explorer-v2 has the existing tonic-web-wasm-client pattern; extracting it into a `@sentrix/chain/grpc-web` subpath is its own PR.
  • Typed message types (Block, Account, etc.) — proto-loader returns loose objects; consumers cast at the use site. A `buf generate` codegen pipeline would emit precise TS types but adds a build dep; revisit when consumers ask.

Completes the SDK surface coverage. Existing doors: evm (viem),
native (REST), bft (WebSocket subs), wallet (signing). New: grpc —
typed wrapper around the chain's sentrix.v1.Sentrix service over
@grpc/grpc-js. Node-only; browser consumers use the gRPC-Web
transport in sentrix-explorer-v2 or wire grpc-web npm directly.

Why a thin wrapper instead of asking callers to load the proto
themselves: bundle the .proto with the npm package version-locked
to the SDK so a chain proto bump can't silently mismatch your
client; centralise the endpoint URL via the same network spec the
rest of the SDK uses; hide the proto-loader → service-stub
plumbing so consumers don't reach into @grpc/grpc-js internals.

Available calls (chain v0.4+):
  - getLatestBlock() / getBlockByHeight(h)
  - getBalance(address)                        — 20-byte hex or Buffer
  - getValidatorSet({ atHeight? })             — full active set + flags
  - getSupply({ atHeight? })                   — minted/burned/circ snapshot
  - getMempool({ limit })                      — pending-tx size + headers
  - streamEvents([filters])                    — server-stream ChainEvent

Older chain hosts (v0.2 / v0.3) return Status::unimplemented for the
newer methods; the SDK forwards the error verbatim so callers can
fall back to JSON-RPC / REST.

Build script copies the .proto from src/grpc-proto/ into
dist/grpc-proto/ so the published package resolves correctly at
runtime. proto-loader path is computed relative to the compiled JS
location via fileURLToPath(import.meta.url).

Verified end-to-end against live grpc.sentrixchain.com:443 —
getLatestBlock() returns block 1678214.
@satyakwok satyakwok enabled auto-merge (squash) May 10, 2026 21:36
@satyakwok satyakwok merged commit 1f75957 into main May 10, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant