Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
markmiro opened this issue Aug 18, 2021 · 1 comment
Open

Comments

@markmiro
Copy link

markmiro commented Aug 18, 2021

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?
@markmiro markmiro changed the title Better errors when calling BaseProvider.request() w Better errors when calling BaseProvider.request() without params Aug 18, 2021
@markmiro markmiro changed the title Better errors when calling BaseProvider.request() without params Better error message when calling BaseProvider.request() without params? Aug 18, 2021
@markmiro
Copy link
Author

After further research, JSON-RPC calls may be able to omit the params.

A Structured value that holds the parameter values to be used during the invocation of the method. This member MAY be omitted.

Source: https://www.jsonrpc.org/specification

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant