MetaMask / metamask-sdk

The simplest yet most secure way to connect your blockchain-based applications to millions of MetaMask Wallet users.
https://metamask.io/sdk/
Other
165 stars 101 forks source link

When adding custome network metamask crashed. #476

Closed swatijindal12 closed 9 months ago

swatijindal12 commented 10 months ago

Code sample

i am using this code

try { console.log("hello2"); await ethereum.request({ method: 'wallet_switchEthereumChain', params: [{ chainId: '0x483' }], }); } catch (switchError) { console.log("hello3"); // This error code indicates that the chain has not been added to MetaMask. if (switchError.code === 4902) { try { console.log("hello4"); await ethereum.request({ method: 'wallet_addEthereumChain', params: [ { chainId: '0x483', chainName: 'Quorum', rpcUrls: ['https://...........'] , }, ], }); } catch (addError) { // handle "add" error } } // handle other "switch" errors }

When i am adding custome network in mobile app. Metamask app crashed. 
swatijindal12 commented 10 months ago

Hey @A-Feder Can you please provide me solution?

A-Feder commented 10 months ago

Hi @swatijindal12 , we are reviewing this and will get back to you ASAP. Please, refrain from opening multiple issues for this.

For completeness, I am including the information you already provided below:

When adding custom network MetaMask SDK does not find chain ID and crashes Platform: React Native MetaMask SDK Version: "@metamask/sdk": "^0.1.0" MetaMask App Version: 7.10.0 (Android)

Additional Info: Ethereum testnets are working fine, others (e.g. Polygon, private networks) present the issue

Screenshot 2023-11-07 at 5 22 22 PM
A-Feder commented 10 months ago

Hey @swatijindal12 , can you please make sure to update the SDK to its latest version and inform me if the issue persists?

swatijindal12 commented 10 months ago

Can you please let me know latest version?

swatijindal12 commented 10 months ago

Right now, i am using metamask SDK version 0.1.0 But when i used lastest version i.e. 0.12.0 Then, I am getting error: Simulator Screen Shot - iPhone 8 - 2023-11-14 at 16 55 30

christopherferreira9 commented 10 months ago

Hi @swatijindal12 ! The latest version of the SDK is 0.12.0. Can you please try our reactNative Example to see if the issue still persists?

Also, about the chainSwitching issue you reported, there is currently an issue we're investigating related to the error codes being returned. For the time being, you'll be able to act on both error codes (even though only one should be used) by checking:

if (error.code === -32603 || error.code === 4902) {
    // Add Chain
}

We're sorry for the inconvenience.

swatijindal12 commented 10 months ago

Okay. Will try & let you know.

swatijindal12 commented 9 months ago

Hey @A-Feder , i am facing one more issue when i am connecting metamask through mobile app in my application then i save provider & signer in the context. But when i integrate smart contarct using ethers & sign tx using metamask i have to again connect to metamask & got provider.

The issue is that i have to reconnect metamask everytime in mobile app.

Screenshot 2023-11-21 at 5 32 42 PM
christopherferreira9 commented 9 months ago

Hi @swatijindal12 ! Can you please share the specific steps to reproduce this issue?

swatijindal12 commented 9 months ago

Hi, Once we have connected with sdk and execute smart contract method after that when we try to execute smart contract method again, we are getting this error "Error: Error: MetaMask is not connected/installed, please call eth_requestAccounts to connect first." To resolve this issue as per the documentation - "You can configure the SDK using any options and call any provider API methods. Always call eth_requestAccounts using ethereum.request(args) first, since it prompts the installation or connection popup to appear." To unblock us, currently before calling any smart contract method i am calling wallet connect method.

christopherferreira9 commented 9 months ago

Hi! That's correct, that should always be the first step. Keep in mind that when using deeplinks it needs to come from the user interaction so that it actually acts as a deeplink and establishes the connection. Without the exact contract call you're trying to execute we are unable to replicate your issue. Would it be possible to share that piece of code?

swatijindal12 commented 9 months ago

WalletConnectContext.txt

Here i attached. Please let me know.

christopherferreira9 commented 9 months ago

Hi @swatijindal12 ! We will be updating the reactNativeDemo in the coming days to take advantage of the sdk-react package long side the hooks that it provides. This should ease the use of the SDK without having to use a custom context and in the end simplify your code. We'll update this issue once it is available.

christopherferreira9 commented 9 months ago

Hi @swatijindal12 ! We recently updated the reactNativeDemo. You can find the docs for it here. Also, for future reference, we recently added a reactNative demo that uses expo.