0

I'd like to prevent a user from entering my dapp until they have registered my token with MetaMask.

I accomplish this using the code below, which is executed the moment the user is about to enter the dapp:

const wasAdded = await ethereum.request({
        method: "wallet_watchAsset",
        params: {
            type: "ERC20",
            options: {
                address: TOKEN_ADDRESS,
                symbol: TOKEN_SYMBOL,
                decimals: 18,
                image: "",
            },
        },
    });

If wasAdded returns false, I prevent the user from entering the dapp.

The problem is, this code will ALWAYS show a prompt to the user to register the token, even if it is already registered.

Is there any way of checking if a token is already registered before triggering this prompt?

If not, what are the alternatives? It's not feasible to show a pointless prompt every time the user launches the dapp.

0

There is no way to check if it is registered

Instead, you default to unregistered tokens for all users, and when the user first registers, you record them so they don't need to be displayed to the user the next time.

Or it can be displayed inconspicuously in case a user removes the token, and it can be re-registered.

2
  • Thanks. That's disappointing. I'd rather that MetaMask record this and I could query MetaMask, this way the state couldn't go out of sync. Aug 19 at 18:36
  • Unfortunately, you have to do it yourself
    – zmy
    Aug 21 at 2:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.