snaps icon indicating copy to clipboard operation
snaps copied to clipboard

Automatic connections FAILED on local setup

Open noahsilencelab opened this issue 1 year ago • 10 comments

Hi team,

Today, I tried your new feature https://docs.metamask.io/snaps/how-to/allow-automatic-connections/ but immediately got some weird error that I couldn't debug myself. Please shed some light for my debugging. The error is thrown after I send RPC wallet_requestSnaps like below:

    return await provider.request({
      method: 'wallet_requestSnaps',
      params: {
        [SNAP_ID]: snapVersion
          ? {
              version: snapVersion,
            }
          : {},
      } as any,
    });

The error:

Screenshot 2024-07-02 at 20 58 36

Environment:

  • Chrome + Flask MetaMask
  • Node v18.20.2

Metamask dependencies package.json:

    "@metamask/eth-sig-util": "^7.0.1",
    "@metamask/keyring-api": "^1.1.0",
    "@metamask/snaps-sdk": "^5.0.0",
    "@metamask/snaps-types": "^3.1.0",
    "@metamask/snaps-ui": "^3.1.0",
    "@metamask/utils": "^8.5.0",

Snap Manifest:

{
  "version": "1.2.9-alpha.2",
  "description": "Silent Shard creates a distributed self-custody account in MetaMask by generating a Distributed Private key between the browser extension and the Silent Shard mobile app using Multi-Party Computation (MPC). Thereby enabling a seamless 2FA experience for secure transactions.",
  "proposedName": "Silent Shard",
  "repository": {
    "type": "git",
    "url": "https://www.npmjs.com/package/@silencelaboratories/silent-shard-snap-staging"
  },
  "source": {
    "shasum": "kgUGyPyxOt+5t2kbxCOHu4vPY0l+oj0EvWda5vOY8B4=",
    "location": {
      "npm": {
        "filePath": "dist/bundle.js",
        "iconPath": "images/silentShardLogo.svg",
        "packageName": "@silencelaboratories/silent-shard-snap-staging",
        "registry": "https://registry.npmjs.org/"
      }
    }
  },
  "initialConnections": {
    "https://snap-staging.silencelaboratories.com": {},
    "http://localhost:3000": {}
  },
  "initialPermissions": {
    "endowment:keyring": {
      "allowedOrigins": [
        "https://snap-staging.silencelaboratories.com",
        "http://localhost:3000"
      ]
    },
    "snap_dialog": {},
    "snap_notify": {},
    "snap_manageState": {},
    "endowment:network-access": {},
    "endowment:rpc": {
      "allowedOrigins": [
        "https://snap-staging.silencelaboratories.com",
        "http://localhost:3000"
      ]
    },
    "snap_getEntropy": {},
    "snap_manageAccounts": {}
  },
  "manifestVersion": "0.1"
}

noahsilencelab avatar Jul 02 '24 13:07 noahsilencelab

Hi, please update your dapp connect code to use a string as the key for the Snap ID instead of an array, like so:

await window.ethereum.request({
  "method": "wallet_requestSnaps",
  "params": [
    {
      `${SNAP_ID}`: {
        "version": `^${snapVersion}`
      }
    }
  ]
});

Please let me know if you still see the error after making this change.

Montoya avatar Jul 02 '24 14:07 Montoya

Hi, its not an array but a Computed property names syntax. It's actually a string key.

noahsilencelab avatar Jul 02 '24 14:07 noahsilencelab

What is the value of SNAP_ID? Usually this error is the result of an invalid ID.

Montoya avatar Jul 02 '24 15:07 Montoya

The value of SNAP_ID local:http://localhost:8080

noahsilencelab avatar Jul 02 '24 16:07 noahsilencelab

And just to be certain, snapVersion is resolving to a string?

Montoya avatar Jul 02 '24 16:07 Montoya

snapVersion is an empty string in this case

noahsilencelab avatar Jul 02 '24 17:07 noahsilencelab

Hmmm... what happens if you remove it entirely? Just:

return await provider.request({
  method: 'wallet_requestSnaps',
  params: {
    [SNAP_ID]: {},
  } as any,
});

Montoya avatar Jul 02 '24 18:07 Montoya

Also, sorry, I'm noticing one other things that may or may not be an issue, we have params for wallet_requestSnaps as an array of objects in our docs, may be just optional but you can try:

return await provider.request({
  method: 'wallet_requestSnaps',
  params: [ {
    [SNAP_ID]: {},
  } ] as Array<any>,
});

Montoya avatar Jul 02 '24 18:07 Montoya

If I have params as an array, I will face the error '"params" must be an object.'

Screenshot 2024-07-03 at 12 27 08

noahsilencelab avatar Jul 03 '24 05:07 noahsilencelab

Hmmm... what happens if you remove it entirely? Just:

The same error happened. RPC Error: Expected caveat to have a value property of a non-empty object of snap IDs.: At path: value.type -- Expected the value to satisfy a union of intersection | string, but received: "type".

noahsilencelab avatar Jul 03 '24 05:07 noahsilencelab