Add a BEP20 token to metamask

Is there anyway to add a selected BEP20 token to metamask through Moralis.

I have found this in the MetaMask documentation but the feature is only available for ERC20 tokens.

Does Moralis have its own way of achieving this?

1 Like

Hey @Tommy, hope you are great.

Now moralis does not have a custom function to achive the same (registering a token), but since it have web3 integrated by default (you just need to active it if its need it), you can basically do the same steps in your dapp and it will work in the same way.

Carlos Z

2 Likes

Hi @thecil,

Thank you for your response

I have tried to activate it using the functions in the article however that feature is only available for ERC20 tokens atm.

I will search for another way

Thanks again!

Hey @Tommy

But metamask supports only erc20 tokens. You can’t display NFTs in metamask

Can you give an exact example of token that you want to add? So that we know if it is even possible to do it.

Hi guys,

i’m not trying to add an NFT. I just want to create a button that will automatically add a token to MetaMask. I’ve already found the code to make it work with an ERC20 token but i need it to work with BEP20, i’m not sure if it is possible yet.

If by BEP20 you mean the equivalent of ERC20 on Binance Smart Chain, then it should be possible to do that, maybe you should make sure to select Binance Smart Chain in MetaMask before adding that token.

It works!

Yes thats exactly what i meant.

strangely it only works if you leave the type of token as ERC20 if you change it to BEP20 it doesn’t work

Thank you for your help, you guys are great

can you also post the code here for others that will want to do the same thing in the future?

1 Like

BEP20 = ERC20 , but for bsc

1 Like

Sure, here is the code and the variables are the ones used in the Moralis Dex tutorial


async function addTokenToWallet(){

const tokenAddress = currentTrade.to.address;
const tokenSymbol = currentTrade.to.symbol;
const tokenDecimals = parseInt(currentTrade.to.decimals);
const tokenImage = currentTrade.to.logoURI;

try {
  // wasAdded is a boolean. Like any RPC method, an error may be thrown.
  const wasAdded = await ethereum.request({
    method: 'wallet_watchAsset',
    params: {
      type: 'ERC20', // Initially only supports ERC20, but eventually more!
      options: {
        address: tokenAddress, // The address that the token is at.
        symbol: tokenSymbol, // A ticker symbol or shorthand, up to 5 chars.
        decimals: tokenDecimals, // The number of decimals in the token
        image: tokenImage, // A string url of the token logo
      },
    },
  });

} catch (error) {
  console.log(error);
}

}
2 Likes