Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I want to have "wallet_watchAsset" feature for Mobile platform in MetaMask #226

Closed
ammarvohra opened this issue May 6, 2024 · 9 comments

Comments

@ammarvohra
Copy link

@skibitsky
I want to add the Token to Metamask in Android with code,

Expected Behaviour:
When I click on Unity Button it should redirect me to MetaMask and give popup to add the token with specific ID on ERC1155.

Code:
Method registered in Namespace:

var requiredNamespaces = new RequiredNamespaces
    {
        {
            "eip155", new ProposedNamespace
            {
                Methods = new[]
                {
                    "eth_sendTransaction",
                    "personal_sign",
                    "eth_signTypedData",
                    "wallet_watchAsset",
                    "wallet_addEthereumChain",
                    "wallet_switchEthereumChain"
                },
                Chains = new[]
                {
                    "eip155:245022926"
                },
                Events = new[]
                {
                    "chainChanged",
                    "accountsChanged"
                }
            }
        }
    };

RPC Class for JSON:

[RpcMethod("wallet_watchAsset")]
[RpcRequestOptions(Clock.ONE_MINUTE, 99990)]
public class WalletWatchParams
{
    [JsonProperty(PropertyName = "type")]
    public string type = "1155";


    [JsonProperty(PropertyName = "options")]
    public WalletWatchParamsOptions options = new WalletWatchParamsOptions();

    [Preserve]
    public WalletWatchParams()
    {
    }
}

public class WalletWatchParamsOptions
{
    [JsonProperty(PropertyName = "address")]
    public string address;

    [JsonIgnore]
    public string symbol;

    [JsonIgnore]
    public uint decimals;

    [JsonIgnore]
    public string image;

    [JsonProperty(PropertyName = "tokenId")]
    public string tokenId;

    [Preserve]
    public WalletWatchParamsOptions()
    {
    }
}

Script where I make a call:

WalletWatchParams watchParams = new WalletWatchParams();
watchParams.type = "ERC1155";
watchParams.options = new WalletWatchParamsOptions() { address = web3Params.ExternalAddress[0].Address, tokenId = "3" };
var watchTest = await WalletConnect.Instance.RequestAsync<WalletWatchParams, string>(watchParams);

ERROR:

WalletConnectException: User disapproved requested chains
WalletConnectSharp.Sign.Engine.Request[T,TR] (System.String topic, T data, System.String chainId, System.Nullable`1[T] expiry) (at <1c1f65c00e50451aa8c03f421811df4e>:0)

Another Script with passing chainID:

WalletWatchParams watchParams = new WalletWatchParams();
watchParams.type = "ERC1155";
watchParams.options = new WalletWatchParamsOptions() { address = web3Params.ExternalAddress[0].Address, tokenId = "3" };
var watchTest = await WalletConnect.Instance.RequestAsync<WalletWatchParams, string>(watchParams,"0xe9ac0ce");

Error:

WalletConnectException: Missing or invalid parameter
WalletConnectSharp.Sign.Engine.WalletConnectSharp.Sign.Interfaces.IEnginePrivate.IsValidRequest[T] (System.String topic, WalletConnectSharp.Network.Models.JsonRpcRequest`1[T] request, System.String chainId) (at <1c1f65c00e50451aa8c03f421811df4e>:0)

@skibitsky
Copy link
Member

skibitsky commented May 6, 2024

Hello,

The ERC-1155 token isn't supported. From MetaMask documentation:

Support for ERC-721 and ERC-1155 tokens is experimental and currently only available on the extension (not on mobile)

@ammarvohra
Copy link
Author

Oh! Thanks for the update. I didn't noticed that just skipped that part.

And I have this strange issue coming from some of the users that when they try to add chain by method wallet_addEthereumChain they do not get redirected to the Metamask and on Crashlytics I can see the error of:

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)

They do get the popup to connect Metamask and the connection is successfully build.

@skibitsky
Copy link
Member

skibitsky commented May 7, 2024

Do you use the latest version of the SDK?

@ammarvohra
Copy link
Author

Yes I am

@skibitsky
Copy link
Member

Interesting. Could you please open a new issue with Bug Report template?

@ammarvohra
Copy link
Author

Added: [Issue #227]

@ammarvohra
Copy link
Author

I've one more question is it possible to add Ethereum Chain network before connecting/authorizing to any wallet, because I have a another network which is not in TrustWallet and I want to connect to it. but until and unless I add that network manually it doesn't allow me to authorize.

Thanks for your help

@skibitsky
Copy link
Member

is it possible to add Ethereum Chain network before connecting/authorizing to any wallet

Unfortunately, it is not possible. You should use optional namespaces that include the chain ID of the network. If after connection, namespaces confirmed by the wallet do not include that chain ID, use wallet_addEthereumChain. Ensure that wallet_addEthereumChain is included in the namespaces, as not all wallets support it.

@ammarvohra
Copy link
Author

Okay thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants