@polygonlabs/staking-api-client
v1.0.0
Published
Type-safe REST client for the Polygon Staking API, generated from the registered Zod schemas
Keywords
Readme
@polygonlabs/staking-api-client
Type-safe REST client for the Polygon Staking API, generated with hey-api from the API's committed OpenAPI spec. Every response is validated at runtime with the same Zod schemas the server enforces.
Why this package exists
Before this client, every consumer of the Staking API hand-rolled its own
response types against /api/v2 and /api/v3 — independent copies that
drifted silently whenever the API changed shape. This client is generated
from the same schema registry the server routes and validates with (via
@polygonlabs/staking-api-schemas),
so an API shape change ships as a new package version instead of a silent
break — and a response that doesn't match its schema fails loudly at the
validation boundary rather than corrupting state downstream.
Install
pnpm add @polygonlabs/staking-api-clientUsage
import { client, getAllValidatorsV3 } from '@polygonlabs/staking-api-client';
client.setConfig({ baseUrl: 'https://staking-api.polygon.technology' });
const { data } = await getAllValidatorsV3();Entry points
@polygonlabs/staking-api-client— the fetch-based SDK: one function per API operation, plus the configurableclientsingleton.@polygonlabs/staking-api-client/react— TanStack Query options factories for React apps. Requires the optionalreactand@tanstack/react-querypeer dependencies; the main entry works without them.@polygonlabs/staking-api-client/factory— the underlying hey-api client factory, for constructing independently-configured client instances.
