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.