ox
Version:
Ethereum Standard Library
28 lines • 767 B
JavaScript
/* eslint-disable jsdoc-js/require-example */
import * as z from 'zod/mini';
/**
* Instantiates a JSON-RPC method schema from a `params` and `returns` Zod
* schema. The returned `RpcSchema.Item` also exposes a derived
* `request` schema (`{ method, params }`) for envelope validation.
*
* @example
* ```ts twoslash
* import { z } from 'ox/zod'
*
* const eth_blockNumber = z.RpcSchema.from({
* method: 'eth_blockNumber',
* params: z.optional(z.tuple([])),
* returns: z.Hex.Hex
* })
* ```
*/
export function from(parameters) {
const { method, params, returns } = parameters;
return {
method,
params,
request: z.object({ method: z.literal(method), params }),
returns,
};
}
//# sourceMappingURL=from.js.map