MetaMask / MetaMask/providers

Better error message when calling `BaseProvider.request()` without `params`?

Open
#192 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
268
Forks
130
PR merge metrics
No merged PRs in 30d

Description

**Environment:**
Brave browser with MetaMask v9.8.4 extension installed. Running code in console

---

The following fails with a confusing error: `MetaMask - RPC Error: Cannot read property 'length' of undefined `
```js
window.ethereum
.request({
method: "eth_blockNumber",
})
```

However, this succeeds:

```js
window.ethereum
.request({
method: "eth_blockNumber",
params: [],
})
```

Some methods like `ethereum.request({ method: "eth_requestAccounts" })` don't require `params` to be set, so I spent an embarrassing of time trying to find out why one call worked and the other didn't.

**Context:**

I was trying to figure out why a convenience library was failing and figured that going down a level down to the RPC level might help. I tried the most basic RPC request I could think of (getting block number) when I got this error.

**Possible solutions:**

1. One solution might be for the MetaMask to add `params: []` when no params are specified.
1. Another solution might be to add some more error checking to the BaseProvider [`request`](https://github.com/MetaMask/providers/blob/a5b8ebec8538469849ded71a9385761f6e6efb71/src/BaseProvider.ts#L229) method?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in src/BaseProvider.ts at the BaseProvider.request method linked in the issue, and reproduce the two window.ethereum.request examples to compare omitted params with params: []. Trace where the undefined length error is produced. Done means the no-params call has intentional, user-facing behavior rather than the confusing TypeError, with the chosen behavior reflected in coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.