From d7c0df9dea18e8cdbcc83c99856a2c3842ab74a9 Mon Sep 17 00:00:00 2001 From: MicaiahReid Date: Fri, 28 Jan 2022 14:21:16 -0500 Subject: [PATCH 1/4] 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. --- packages/web3-core-helpers/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/web3-core-helpers/types/index.d.ts b/packages/web3-core-helpers/types/index.d.ts index 2a072af3bc1..9036abf181d 100644 --- a/packages/web3-core-helpers/types/index.d.ts +++ b/packages/web3-core-helpers/types/index.d.ts @@ -216,7 +216,7 @@ export interface RequestItem { export interface JsonRpcPayload { jsonrpc: string; method: string; - params: any[]; + params?: any[]; id?: string | number; } From a0db5d227afdd3999d19d4ac726e746e88557835 Mon Sep 17 00:00:00 2001 From: MicaiahReid Date: Fri, 28 Jan 2022 14:32:38 -0500 Subject: [PATCH 2/4] 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`. --- packages/web3-core-helpers/types/index.d.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/web3-core-helpers/types/index.d.ts b/packages/web3-core-helpers/types/index.d.ts index 9036abf181d..e8f47cdfc22 100644 --- a/packages/web3-core-helpers/types/index.d.ts +++ b/packages/web3-core-helpers/types/index.d.ts @@ -17,9 +17,9 @@ * @date 2018 */ -import * as net from 'net'; -import * as http from 'http'; -import * as https from 'https'; + import * as net from 'net'; + import * as http from 'http'; + import * as https from 'https'; export class formatters { static outputBigNumberFormatter(number: number): number; @@ -222,9 +222,13 @@ export interface JsonRpcPayload { 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 4c1263178e7df860c685a1d01a6a133fb3879f30 Mon Sep 17 00:00:00 2001 From: MicaiahReid Date: Fri, 28 Jan 2022 14:44:37 -0500 Subject: [PATCH 3/4] Remove errant spaces --- packages/web3-core-helpers/types/index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/web3-core-helpers/types/index.d.ts b/packages/web3-core-helpers/types/index.d.ts index e8f47cdfc22..e3ee7650f0a 100644 --- a/packages/web3-core-helpers/types/index.d.ts +++ b/packages/web3-core-helpers/types/index.d.ts @@ -17,9 +17,9 @@ * @date 2018 */ - import * as net from 'net'; - import * as http from 'http'; - import * as https from 'https'; +import * as net from 'net'; +import * as http from 'http'; +import * as https from 'https'; export class formatters { static outputBigNumberFormatter(number: number): number; From 37b886eea531a41631f247706f4380eb926a7c30 Mon Sep 17 00:00:00 2001 From: MicaiahReid Date: Fri, 28 Jan 2022 15:24:37 -0500 Subject: [PATCH 4/4] Add PR #443 to CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c18990dbdbe..c16a47013ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -508,6 +508,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