WalletConnectUnity
WalletConnectUnity copied to clipboard
wallet_addEthereumChain doesn't get redirect to Metamask
Describe the bug Some of my users has this issue that when they try to add chain network, they are not taken back to Metamask from my Game, instead it throws error:
Fatal Exception: java.lang.Exception: WalletConnectException : No matching key with tag: {tag}
at WalletConnectSharp.Sign.Engine.IsValidSessionTopic(WalletConnectSharp.Sign.Engine)
at WalletConnectSharp.Sign.Engine.Request[T,TR](WalletConnectSharp.Sign.Engine)
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[TResult].Start[TStateMachine](System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[TResult])
at WalletConnectSharp.Sign.Engine.Request[T,TR](WalletConnectSharp.Sign.Engine)
at WalletConnectSharp.Sign.WalletConnectSignClient.Request[T,TR](WalletConnectSharp.Sign.WalletConnectSignClient)
at WalletConnectUnity.Core.WalletConnect.RequestAsync[TRequestData,TResponse](WalletConnectUnity.Core.WalletConnect)
To Reproduce Steps to reproduce the behavior:
- I connect metamask and Unity Game on Android
- I came back to my game after authorization and then I click Unity button to add new network on Metamask
- It doesn't take me back to Metamask application
Expected behavior It should take me to Metamask application where a popup appears to add new network chain
Screenshots
Environment
- OS: Build on Windows 10 game running on Android 10
- Unity version 2022.3.20
- WalletConnectUnity Modal v1.1.5
Is this happening in Unity Editor or on a player like Android, iOS, Windows? Android 10
Wallets used for testing Metamask
Additional context None
Hey @ammarvohra, could you please upgrade to v1.1.6 and let me know if the issue persists?
Sure, I'll do it and will update you.
Thanks
@skibitsky still no luck of working, even worse, in this version sometimes users are not getting back to the game after connection is successful. They need to comeback to the game close the Modal view and open and do connection again
@ammarvohra
in this version sometimes users are not getting back to the game after connection is successful. They need to comeback to the game close the Modal view and open and do connection again
Could you please describe the exact steps so I could reproduce them? What version of MetaMask do you have?
still no luck of working,
Do you still get WalletConnectException : No matching key with tag: {tag}
?
Could you please describe the exact steps so I could reproduce them? What version of MetaMask do you have?
Opened my game -> Clicked on button to connect the Metamask -> Metamask opened -> Popup comes to connect the wallet -> Connect pressed -> Doesn't redirect to my game -> Opened my game from app stack -> Closed the WalletConnectModal -> Clicked on connect -> Metamask opens up with connection popup -> Clicked on Connect -> Redirected back to my game.
Do you still get
WalletConnectException : No matching key with tag: {tag}
?`
Yes if Metamask is not opening after the connection this error is thrown, and if Metamask get's open it doesn't throw error but there is also no Popup for adding new Chain Network.
I haven't changed anything related to the redirection in the last release; that may be an issue on the MetaMask side.
... Opened my game from app stack -> Closed the WalletConnectModal -> Clicked on connect -> ...
What happens if you keep the modal open for 5-8 seconds after you open the game instead of closing it immediately?
I haven't changed anything related to the redirection in the last release; that may be an issue on the MetaMask side.
Idk but what I noticed was this that 1.1.4 was having some similar issue, while 1.1.5 was smooth and 1.1.6 got that issue.
What happens if you keep the modal open for 5-8 seconds after you open the game instead of closing it immediately?
Doesn't do anything just keep saying trying to connect or try again.
But the thing I couldn't understand is some people can open the Metamask when they click on Add chain network, but even after waiting for some 10-15 seconds on Metamask the option/popup to add chain doesn't come up.
But the thing I couldn't understand is some people can open the Metamask when they click on Add chain network, but even after waiting for some 10-15 seconds on Metamask the option/popup to add chain doesn't come up.
MetaMask fixed that in the latest release
User's phone configuration: Brand: Samsung Model: Galaxy S20 5G Android Version: Android 13 Metamask version: 7.21.0 Location: Europe/London
Still no luck
User's phone configuration: Brand: Samsung Model: Galaxy S20 5G Android Version: Android 13 Metamask version: 7.21.0 Location: Europe/London
A few more questions 🙏
- Just to make sure I got it right. This user gets
WalletConnectException : No matching key with tag: {tag}
when sendingwallet_addEthereumChain
? - Do they have WalletConnectUnity Modal v1.1.6 or older version?
- In your game, how exactly do you resume session after restart? Do you use
WalletConnect.Instance.TryResumeSessionAsync()
directly or haveResumeSessionOnInit
option enabled in theWalletConnectModal
component? Or do you use another approach? - Have they tried to reinstall the game? Does the issue persist?
- Have they tried to disconnect wallet and connect again? Does the issue persist?
Just to make sure I got it right. This user gets WalletConnectException : No matching key with tag: {tag} when sending wallet_addEthereumChain?
No this uesr doesn't get exception as when clicking on Add chain it take him back to Metamask but Metamask does nothing
Do they have WalletConnectUnity Modal v1.1.6 or older version?
1.1.6
In your game, how exactly do you resume session after restart? Do you use WalletConnect.Instance.TryResumeSessionAsync() directly or have ResumeSessionOnInit option enabled in the WalletConnectModal component? Or do you use another approach?
ResumeSessionOnInit
option is enabled in the WalletConnectModal
Have they tried to reinstall the game? Does the issue persist?
Yeap, same issue
Have they tried to disconnect wallet and connect again? Does the issue persist?
Yeap they reinstall the application everytime, so the previous session get's expired so they need to make a new connection
Okay, it's good that they don't get the exception.
Could you please share a code snippet demonstrating how you detect the need to add a new chain to MetaMask and how you add and switch the chain?
Here is the code:
public async void OnExternalWalletConnected()
{
while (!WalletConnect.Instance.IsConnected)
await Task.Delay(25);
var chainNew = new WalletConnectUnity.Core.Evm.EthereumChain
{
chainIdHex = "0x" + web3Params.ChainID.ToString("X").ToLower(),
blockExplorerUrls = new string[] { web3Params.BlockExplorerURL },
name = web3Params.NetworkName,
nativeCurrency = new Currency(web3Params.CurrencySymbol, web3Params.CurrencySymbol, 18),
rpcUrls = new string[] { web3Params.NetworkURL }
};
WalletConnectUnity.Core.Evm.WalletAddEthereumChain walletAddEthereumChain = new WalletConnectUnity.Core.Evm.WalletAddEthereumChain
{
chainNew
};
var connectNetwork = await WalletConnect.Instance.RequestAsync<WalletConnectUnity.Core.Evm.WalletAddEthereumChain, string>(walletAddEthereumChain);
Debug.LogError(connectNetwork);
}
Same issue! I was trying to switching the chain after user successfully connected to session. @skibitsky @ammarvohra GOT THE ERROR - User disapproved requested chains
Below is my function code to change the chain -
private async Task CheckAndChange_ChainAsync()
{
string activeChain = WalletConnect.Instance.ActiveChainId;
Debug.Log("Active chain: " + activeChain);
Chain to_add_chain = ChainConstants.Chains.Arbitrum;
try
{
Debug.Log("Switching chain...");
await WalletConnect.Instance.SwitchEthereumChainAsync(new EthereumChain(to_add_chain));
Debug.Log("Chain switched!");
}
catch (System.Exception e)
{
Debug.Log("error: " + e.Message);
}
}
Below is the code for extention method provided by WalletConnectUnity.Core.Evm i.e SwitchEthereumChainAsync
public static async Task SwitchEthereumChainAsync(this IWalletConnect walletConnect, EthereumChain ethereumChain)
{
if (ethereumChain == null)
throw new ArgumentNullException(nameof(ethereumChain));
var ciap2ChainId = $"eip155:{ethereumChain.chainIdDecimal}";
if (!walletConnect.ActiveSession.Namespaces.TryGetValue("eip155", out var @namespace)
|| [email protected](ciap2ChainId))
{
var request = new WalletAddEthereumChain(ethereumChain);
try
{
await walletConnect.RequestAsync<WalletAddEthereumChain, string>(request);
}
catch (WalletConnectException e)
{
Debug.Log("Error inside: " + e.Message);
}
}
var data = new WalletSwitchEthereumChain(ethereumChain.chainIdHex);
await walletConnect.RequestAsync<WalletSwitchEthereumChain, string>(data);
}
and below is my namespace from which i am creating the session
var requiredNamespaces = new RequiredNamespaces
{
{
"eip155", new ProposedNamespace
{
Methods = new[]
{
"eth_sendTransaction",
"eth_signTransaction",
"eth_sign",
"personal_sign",
"eth_signTypedData",
"wallet_addEthereumChain",
"wallet_switchEthereumChain"
},
Chains = new[]
{
"eip155:42161"
},
Events = new[]
{
"chainChanged",
"accountsChanged"
}
}
}
};
@deveshbeniwal could you please open a new issue with the bug report template? The error message you're getting is different than the one reported here.
@deveshbeniwal could you please open a new issue with the bug report template? The error message you're getting is different than the one reported here.
Added - https://github.com/WalletConnect/WalletConnectUnity/issues/232#issue-2323323352
It is holding us back from doing full rollout and marketing please help us to resolve this.