From 63b5e62bd23effb44e613b9d31a86fa182fa70d6 Mon Sep 17 00:00:00 2001 From: Micaiah Reid Date: Tue, 8 Feb 2022 14:01:32 -0500 Subject: [PATCH 1/2] 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> --- CHANGELOG.md | 1 + packages/web3-core-helpers/types/index.d.ts | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81ee4f921b1..bd504c3606d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -509,6 +509,7 @@ Released with 1.0.0-beta.37 code base. - Update the documentation for `methods.myMethod.estimateGas` (#4702) - Fix typos in REVIEW.md and TESTING.md (#4691) - Fix encoding for "0x" string values (#4512) +- Fix jsonrpc payload and response types (#4743) ### Changed diff --git a/packages/web3-core-helpers/types/index.d.ts b/packages/web3-core-helpers/types/index.d.ts index 2a072af3bc1..e3ee7650f0a 100644 --- a/packages/web3-core-helpers/types/index.d.ts +++ b/packages/web3-core-helpers/types/index.d.ts @@ -216,15 +216,19 @@ export interface RequestItem { export interface JsonRpcPayload { jsonrpc: string; method: string; - params: any[]; + params?: any[]; id?: string | number; } export interface JsonRpcResponse { jsonrpc: string; - id: number; + id: string | number; result?: any; - error?: string; + error?: { + readonly code?: number; + readonly data?: unknown; + readonly message: string; + }; } export interface RevertInstructionError extends Error { From cc643167d3468a51b0057f138107ca3070f50ae4 Mon Sep 17 00:00:00 2001 From: jdevcs Date: Tue, 8 Feb 2022 20:55:26 +0100 Subject: [PATCH 2/2] changelog update --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd504c3606d..0f6d1c7d8ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -509,7 +509,7 @@ Released with 1.0.0-beta.37 code base. - Update the documentation for `methods.myMethod.estimateGas` (#4702) - Fix typos in REVIEW.md and TESTING.md (#4691) - Fix encoding for "0x" string values (#4512) -- Fix jsonrpc payload and response types (#4743) +- Fix jsonrpc payload and response types (#4743) (#4761) ### Changed