api-specs icon indicating copy to clipboard operation
api-specs copied to clipboard

Error on wallet_requestSnaps

Open vandan opened this issue 1 year ago • 2 comments

Looks like there is an issue with the wallet_requestSnaps method (possibly with the format of the example)

From @Montoya

It’s this one: https://docs.metamask.io/wallet/reference/wallet_requestsnaps/ If you click Send Request you get an error, I think because the parameters are formatted wrong

vandan avatar Mar 01 '24 00:03 vandan

Here is what it looks like in the current docs as by-position:

image

if I just add by-name, we get this:

image

which isn't correct.

in JSON-RPC you should really be able to swap between by-params and by-name, but the way that the method for wallet_requestSnaps is built now it does not conform to the by-name spec for JSON-RPC

by-name: params MUST be an Object, with member names that match the Server expected parameter names. The absence of expected names MAY result in an error being generated. The names MUST match exactly, including case, to the method's expected parameters.

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

Currently each "npm:@metamask/example-snap" is in the place of the parameter name.

My recommendation here is that the implementation for wallet_requestSnaps should be by-params:

await window.ethereum.request({
  "method": "wallet_requestSnaps",
  "params": [
    {
      "npm:@metamask/example-snap": {},
      "npm:fooSnap": {
        "version": "^1.0.2"
      }
    }
  ]
});

This also lines up with the rest of our wallet API (except for the mistake that was wallet_watchAsset that got out with by-name).

shanejonas avatar Mar 08 '24 15:03 shanejonas

we removed the snap methods in this PR because they are dynamic by-name, which isnt supported, the downstream tools needs some work to allow that to happen. maybe an x- extension like x-dynamic-by-name: true.

shanejonas avatar Apr 30 '24 13:04 shanejonas