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

Open
#192 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

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

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.

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

window.ethereum
  .request({
    method: "eth_blockNumber",
  })

However, this succeeds:

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.
  2. Another solution might be to add some more error checking to the BaseProvider request method?
Dominant language
TypeScript
Stars
268
Forks
130
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from MetaMask/providers

All issues in MetaMask/providers

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.