Automatic connections FAILED on local setup
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:
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"
}
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.
Hi, its not an array but a Computed property names syntax. It's actually a string key.
What is the value of SNAP_ID? Usually this error is the result of an invalid ID.
The value of SNAP_ID local:http://localhost:8080
And just to be certain, snapVersion is resolving to a string?
snapVersion is an empty string in this case
Hmmm... what happens if you remove it entirely? Just:
return await provider.request({
method: 'wallet_requestSnaps',
params: {
[SNAP_ID]: {},
} as any,
});
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>,
});
If I have params as an array, I will face the error '"params" must be an object.'
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".