From 5e905000b7842e9099465b88624daf52011e3b5c Mon Sep 17 00:00:00 2001 From: Kanthesha Devaramane Date: Tue, 13 Aug 2024 15:21:14 +0100 Subject: [PATCH] Fixed SafeEventEmitterProvider invalid default params (#4603) ## Explanation The SafeEventEmitterProvider is failing to send net_version requests correctly because it's using an empty object as the default params when none are provided. While some methods do use an object for params, the vast majority use an array instead. Passing an empty object as the params for a method that has array parameters can result in failure (as is the case for net_version). ## References * Fixes #4595 ## Changelog ### `@metamask/eth-json-rpc-provider` - **FIXED**: The default value for params in the request has been replaced from empty object to an empty array ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] I've highlighted breaking changes using the "BREAKING" category above as appropriate --- .../src/safe-event-emitter-provider.test.ts | 1 - .../src/safe-event-emitter-provider.ts | 25 ++++++++++--------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/eth-json-rpc-provider/src/safe-event-emitter-provider.test.ts b/packages/eth-json-rpc-provider/src/safe-event-emitter-provider.test.ts index dfab3eaa08..3503ed284b 100644 --- a/packages/eth-json-rpc-provider/src/safe-event-emitter-provider.test.ts +++ b/packages/eth-json-rpc-provider/src/safe-event-emitter-provider.test.ts @@ -511,7 +511,6 @@ describe('convertEip1193RequestToJsonRpcRequest', () => { id: 'mock-id', jsonrpc: '2.0', method: 'test', - params: {}, }); }); }); diff --git a/packages/eth-json-rpc-provider/src/safe-event-emitter-provider.ts b/packages/eth-json-rpc-provider/src/safe-event-emitter-provider.ts index 5bb562f858..69ed56eee7 100644 --- a/packages/eth-json-rpc-provider/src/safe-event-emitter-provider.ts +++ b/packages/eth-json-rpc-provider/src/safe-event-emitter-provider.ts @@ -31,18 +31,19 @@ export function convertEip1193RequestToJsonRpcRequest< >( eip1193Request: Eip1193Request, ): JsonRpcRequest> { - const { - id = uuidV4(), - jsonrpc = '2.0', - method, - params = {}, - } = eip1193Request; - return { - id, - jsonrpc, - method, - params, - }; + const { id = uuidV4(), jsonrpc = '2.0', method, params } = eip1193Request; + return params + ? { + id, + jsonrpc, + method, + params, + } + : { + id, + jsonrpc, + method, + }; } /**