feat(grpc): Node-side @sentrix/chain/grpc client + bundled .proto#16
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Available calls (chain v0.4+)
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