Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 63b5e62

Browse files
MicaiahReidjdevcs
andauthored
Fix jsonrpc payload and response types (#4743)
* Make JsonRpcPayload's `params` field optional Currently jsonrpc.js uses `params: params || []` in the `toPayload` function, so this type update makes the `params` field optional to match. * Fix JsonRpcResponse type Update `id` to accept `string | number` - this now matches the `isValidResponse` function in `jsonrpc.js`. Update `error` to accept an object with optional `code`, `data`, and non-optional `message` fields to more closely match the [JSON RPC spec](https://www.jsonrpc.org/specification#error_object) and the `ErrorResponse` function in `errors.js`. * Remove errant spaces * Add PR #443 to CHANGELOG Co-authored-by: jdevcs <86780488+jdevcs@users.noreply.github.com>
1 parent 2a10e24 commit 63b5e62

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ Released with 1.0.0-beta.37 code base.
509509
- Update the documentation for `methods.myMethod.estimateGas` (#4702)
510510
- Fix typos in REVIEW.md and TESTING.md (#4691)
511511
- Fix encoding for "0x" string values (#4512)
512+
- Fix jsonrpc payload and response types (#4743)
512513

513514

514515
### Changed

packages/web3-core-helpers/types/index.d.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,15 +216,19 @@ export interface RequestItem {
216216
export interface JsonRpcPayload {
217217
jsonrpc: string;
218218
method: string;
219-
params: any[];
219+
params?: any[];
220220
id?: string | number;
221221
}
222222

223223
export interface JsonRpcResponse {
224224
jsonrpc: string;
225-
id: number;
225+
id: string | number;
226226
result?: any;
227-
error?: string;
227+
error?: {
228+
readonly code?: number;
229+
readonly data?: unknown;
230+
readonly message: string;
231+
};
228232
}
229233

230234
export interface RevertInstructionError extends Error {

0 commit comments

Comments
 (0)