On Mobile Devices, Metamask Deeplink on Metamask browser is giving JSON RPC Error due to ChainID Not Detected

I am developing Crypto website using javascript. I have ‘Wallet Connect’ button to connect to various wallets, like, MetaMask, Trust Wallet, etc. On Desktop/ Laptop, I am connecting to Browser extensions for all wallets, and my code is working fine, able to connect to wallet extenstions, and can see account balances and can make payment. But on Mobile devices, I am having issues. I open my website in mobile device, and use MetaMask wallet app. Opening MetaMask deeplink in MetaMask browser, I am able to connect but unable to see account balances , nor can I make any payment using MetaMask. It is showing internal JSON RPC error. Error is - “{“jsonrpc”:“2.0”,“id”:“927677f5-8205-4ff4-af7f-a349e1f93c9b”,“error”:{“code”:-32603,“message”:“Internal JSON-RPC error.”,“data”:{“code”:-32000,“message”:“execution reverted”}}}”

I would appreciate any help in this issue.

1 Like

Hi is it IOS or Android and how are you configuring the network are you using the right endpoint, could you share more please

Hello, Thank You for your reply.
I am currently testng for Android, and using Binance Smart Chain Network.
The Endpoint URL is: ‘bsc-dataseed dot binance dot org/’

My BNB Balance is being Fetched, but not USDT.
The Same Code is working for Trust Wallet App on Mobile Device.

My Metmask Connection and USDT Balance retreival Code:


getElement("metamask").onclick = async function connectMeta() {
     const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
          
     if (typeof window.ethereum !== "undefined") {
            window.ethereum.request({
              method: "eth_requestAccounts"
            }).then((accounts) => {
              web3 = new Web3(window.ethereum);
              account = accounts[0];
              isConnected = true;
              console.log("Connected Successfully!: " + account);

              getElement("popup").style.display = "none";
              getElement("connectWallet").innerHTML =
                "Connected: " +
                account.substring(0, 4) +
                "....." +
                account.substring(account.length - 4, account.length);
              getElement("connectWallet").onclick = "";
			  
              addEthChain();
              
              try {
                window.ethereum.request({
                  method: 'wallet_switchEthereumChain',
                  params: [{
                    chainId: '0x38' // BSC mainnet chainId
                  }],
                });
              } catch (error) {
                if (error.code === 4001) {
                  // User rejected the network switch
                  window.alert('Network switch was rejected by user');
                } else {
                  // Some other error
                  console.error('Some Error switching network:', error);
                }
              }

              retreiveUSDTBal(web3, account);
              retreiveBNBBal(web3, account);

              getElement("buyPart").style.display = "block";

            });

      } else {
            if (isMobile) {
              window.open('https://metamask.app.link/aiclastrocoin.com/presale');
              getElement("error").textContent = "You are Here.";
            } else {

              alert("First Install Metamask");
              console.log("Metamask is not Installed");
            }
     }
}


async function retreiveUSDTBal(web3, address) {

          const usdtContract = new web3.eth.Contract(usdtAbi, usdtContractAddress);

          try {
            const balanceWei = await usdtContract.methods.balanceOf(address).call();
            const balanceUSDT = (Number(balanceWei) / (10 ** 18)).toFixed(8); // Convert the divisor to BigInt
            balUSDT = balanceUSDT;

            console.log('USDT Balance:', balanceUSDT, 'USDT');
            getElement("usdtBalance").textContent = balanceUSDT;

          } catch (error) {
            var err = JSON.stringify(error);
            console.error('Error retrieving USDT balance:', error);
            getElement("usdtBalance").textContent = err;
            window.open('mailto:support@aiclastrocoin.com?subject=error&body=' + err);
          }
}


async function retreiveBNBBal(web3, address) {
          const BSCContractAddress = '0xB8c77482e45F1F44dE1745F52C74426C631bDD52';
          const BSCAbi = [{
              "constant": true,
              "inputs": [],
              "name": "name",
              "outputs": [{
                "name": "",
                "type": "string"
              }],
              "payable": false,
              "stateMutability": "view",
              "type": "function"
            },
            {
              "constant": true,
              "inputs": [],
              "name": "symbol",
              "outputs": [{
                "name": "",
                "type": "string"
              }],
              "payable": false,
              "stateMutability": "view",
              "type": "function"
            },
            {
              "constant": true,
              "inputs": [],
              "name": "decimals",
              "outputs": [{
                "name": "",
                "type": "uint8"
              }],
              "payable": false,
              "stateMutability": "view",
              "type": "function"
            },
            {
              "constant": true,
              "inputs": [{
                "name": "_owner",
                "type": "address"
              }],
              "name": "balanceOf",
              "outputs": [{
                "name": "balance",
                "type": "uint256"
              }],
              "payable": false,
              "stateMutability": "view",
              "type": "function"
            }
            // ... Add more functions as needed based on your requirements
          ];

          const BSCContract = new web3.eth.Contract(BSCAbi, BSCContractAddress);

          web3.eth.getBalance(address)
            .then((balance) => {
              const bnbBalance = (parseFloat(web3.utils.fromWei(balance, 'ether'))).toFixed(8);
              balBNB = bnbBalance;
              console.log('BNB Balance:', bnbBalance, 'BNB');
            });
          
}

Hi thanks for sharing is it mainnet I checked I don’t see any USDT only USDC Address 0xB8c77482e45F1F44dE1745F52C74426C631bDD52 | BscScan please let me know if I’m missing something and you are on testnet

Hello, Thanks a lot for your help. Here is the link for BUSD-T on BSC Scan:

bscscan - address/0x55d398326f99059ff775485246999027b3197955

I am using USDT ABI :slight_smile: Not sure if any issue with ABI.

“usdtCA”: “0x55d398326f99059ff775485246999027b3197955”,

“usdtABI”: [
{
“inputs”: ,
“payable”: false,
“stateMutability”: “nonpayable”,
“type”: “constructor”
},
{
“anonymous”: false,
“inputs”: [
{
“indexed”: true,
“internalType”: “address”,
“name”: “owner”,
“type”: “address”
},
{
“indexed”: true,
“internalType”: “address”,
“name”: “spender”,
“type”: “address”
},
{
“indexed”: false,
“internalType”: “uint256”,
“name”: “value”,
“type”: “uint256”
}
],
“name”: “Approval”,
“type”: “event”
},
{
“anonymous”: false,
“inputs”: [
{
“indexed”: true,
“internalType”: “address”,
“name”: “previousOwner”,
“type”: “address”
},
{
“indexed”: true,
“internalType”: “address”,
“name”: “newOwner”,
“type”: “address”
}
],
“name”: “OwnershipTransferred”,
“type”: “event”
},
{
“anonymous”: false,
“inputs”: [
{
“indexed”: true,
“internalType”: “address”,
“name”: “from”,
“type”: “address”
},
{
“indexed”: true,
“internalType”: “address”,
“name”: “to”,
“type”: “address”
},
{
“indexed”: false,
“internalType”: “uint256”,
“name”: “value”,
“type”: “uint256”
}
],
“name”: “Transfer”,
“type”: “event”
},
{
“constant”: true,
“inputs”: ,
“name”: “_decimals”,
“outputs”: [
{
“internalType”: “uint8”,
“name”: “”,
“type”: “uint8”
}
],
“payable”: false,
“stateMutability”: “view”,
“type”: “function”
},
{
“constant”: true,
“inputs”: ,
“name”: “_name”,
“outputs”: [
{
“internalType”: “string”,
“name”: “”,
“type”: “string”
}
],
“payable”: false,
“stateMutability”: “view”,
“type”: “function”
},
{
“constant”: true,
“inputs”: ,
“name”: “_symbol”,
“outputs”: [
{
“internalType”: “string”,
“name”: “”,
“type”: “string”
}
],
“payable”: false,
“stateMutability”: “view”,
“type”: “function”
},
{
“constant”: true,
“inputs”: [
{
“internalType”: “address”,
“name”: “owner”,
“type”: “address”
},
{
“internalType”: “address”,
“name”: “spender”,
“type”: “address”
}
],
“name”: “allowance”,
“outputs”: [
{
“internalType”: “uint256”,
“name”: “”,
“type”: “uint256”
}
],
“payable”: false,
“stateMutability”: “view”,
“type”: “function”
},
{
“constant”: false,
“inputs”: [
{
“internalType”: “address”,
“name”: “spender”,
“type”: “address”
},
{
“internalType”: “uint256”,
“name”: “amount”,
“type”: “uint256”
}
],
“name”: “approve”,
“outputs”: [
{
“internalType”: “bool”,
“name”: “”,
“type”: “bool”
}
],
“payable”: false,
“stateMutability”: “nonpayable”,
“type”: “function”
},
{
“constant”: true,
“inputs”: [
{
“internalType”: “address”,
“name”: “account”,
“type”: “address”
}
],
“name”: “balanceOf”,
“outputs”: [
{
“internalType”: “uint256”,
“name”: “”,
“type”: “uint256”
}
],
“payable”: false,
“stateMutability”: “view”,
“type”: “function”
},
{
“constant”: false,
“inputs”: [
{
“internalType”: “uint256”,
“name”: “amount”,
“type”: “uint256”
}
],
“name”: “burn”,
“outputs”: [
{
“internalType”: “bool”,
“name”: “”,
“type”: “bool”
}
],
“payable”: false,
“stateMutability”: “nonpayable”,
“type”: “function”
},
{
“constant”: true,
“inputs”: ,
“name”: “decimals”,
“outputs”: [
{
“internalType”: “uint8”,
“name”: “”,
“type”: “uint8”
}
],
“payable”: false,
“stateMutability”: “view”,
“type”: “function”
},
{
“constant”: false,
“inputs”: [
{
“internalType”: “address”,
“name”: “spender”,
“type”: “address”
},
{
“internalType”: “uint256”,
“name”: “subtractedValue”,
“type”: “uint256”
}
],
“name”: “decreaseAllowance”,
“outputs”: [
{
“internalType”: “bool”,
“name”: “”,
“type”: “bool”
}
],
“payable”: false,
“stateMutability”: “nonpayable”,
“type”: “function”
},
{
“constant”: true,
“inputs”: ,
“name”: “getOwner”,
“outputs”: [
{
“internalType”: “address”,
“name”: “”,
“type”: “address”
}
],
“payable”: false,
“stateMutability”: “view”,
“type”: “function”
},
{
“constant”: false,
“inputs”: [
{
“internalType”: “address”,
“name”: “spender”,
“type”: “address”
},
{
“internalType”: “uint256”,
“name”: “addedValue”,
“type”: “uint256”
}
],
“name”: “increaseAllowance”,
“outputs”: [
{
“internalType”: “bool”,
“name”: “”,
“type”: “bool”
}
],
“payable”: false,
“stateMutability”: “nonpayable”,
“type”: “function”
},
{
“constant”: false,
“inputs”: [
{
“internalType”: “uint256”,
“name”: “amount”,
“type”: “uint256”
}
],
“name”: “mint”,
“outputs”: [
{
“internalType”: “bool”,
“name”: “”,
“type”: “bool”
}
],
“payable”: false,
“stateMutability”: “nonpayable”,
“type”: “function”
},
{
“constant”: true,
“inputs”: ,
“name”: “name”,
“outputs”: [
{
“internalType”: “string”,
“name”: “”,
“type”: “string”
}
],
“payable”: false,
“stateMutability”: “view”,
“type”: “function”
},
{
“constant”: true,
“inputs”: ,
“name”: “owner”,
“outputs”: [
{
“internalType”: “address”,
“name”: “”,
“type”: “address”
}
],
“payable”: false,
“stateMutability”: “view”,
“type”: “function”
},
{
“constant”: false,
“inputs”: ,
“name”: “renounceOwnership”,
“outputs”: ,
“payable”: false,
“stateMutability”: “nonpayable”,
“type”: “function”
},
{
“constant”: true,
“inputs”: ,
“name”: “symbol”,
“outputs”: [
{
“internalType”: “string”,
“name”: “”,
“type”: “string”
}
],
“payable”: false,
“stateMutability”: “view”,
“type”: “function”
},
{
“constant”: true,
“inputs”: ,
“name”: “totalSupply”,
“outputs”: [
{
“internalType”: “uint256”,
“name”: “”,
“type”: “uint256”
}
],
“payable”: false,
“stateMutability”: “view”,
“type”: “function”
},
{
“constant”: false,
“inputs”: [
{
“internalType”: “address”,
“name”: “recipient”,
“type”: “address”
},
{
“internalType”: “uint256”,
“name”: “amount”,
“type”: “uint256”
}
],
“name”: “transfer”,
“outputs”: [
{
“internalType”: “bool”,
“name”: “”,
“type”: “bool”
}
],
“payable”: false,
“stateMutability”: “nonpayable”,
“type”: “function”
},
{
“constant”: false,
“inputs”: [
{
“internalType”: “address”,
“name”: “sender”,
“type”: “address”
},
{
“internalType”: “address”,
“name”: “recipient”,
“type”: “address”
},
{
“internalType”: “uint256”,
“name”: “amount”,
“type”: “uint256”
}
],
“name”: “transferFrom”,
“outputs”: [
{
“internalType”: “bool”,
“name”: “”,
“type”: “bool”
}
],
“payable”: false,
“stateMutability”: “nonpayable”,
“type”: “function”
},
{
“constant”: false,
“inputs”: [
{
“internalType”: “address”,
“name”: “newOwner”,
“type”: “address”
}
],
“name”: “transferOwnership”,
“outputs”: ,
“payable”: false,
“stateMutability”: “nonpayable”,
“type”: “function”
}
]

thanks could you please check if your contract address and abi file have the same version

Hello, thanks a lot for your help. I am not sure, what exactly do you mean by “Abi File Version”, but I am using the exact ABI provided by BSCScan. Thanks

Would you mind checking with Binance team about USDT Abi and then come back I’ll check something on our side too

Hi, I will contact Binance team. But I am not very hopeful, because the code works fine on many wallets ( including MetaMask) for Browser extensions in Chrome, Edge, Firefox, Brave web browsers. We have tested them all, and passed. The main issue we face now is with MetaMask deeplink on MetaMask browser using mobile device. We are not able to see USDT Balance and not able to make payment (Buy crypto). Please let me know if you or your team can suggest some probable resolution. I appreciate your help on this matter. Thank you.

Thank you, please check this post: WalletConnect v2 Deep Linking with Metamask Mobile - #4 by Naruto

I’ve also noticed that you are using browser on mobile, why not metmask in app browser, please let me know if it’s clear.

Have you tried our ios sdk: Use MetaMask SDK with iOS | MetaMask developer documentation maybe it would be easier

Hello, Thanks for Replying.
When Someone opens my website in a Non-Web3 Browser, like Chrome, in Mobile, my code will redirect them to/ open the Wallet, using Deeplink, then go to their in-built, Web3 Browser, like of MetaMask Mobile app, and then execute the Rest of the code in their Browser.
The Problem is after Connection in their Web3 Wallet App Browser, It is not fetching the Usdt Balance, but is rightly fetching the BNB Balance. I have shared the code before.
In PC/Laptop, everthing is good, Connection, Fetching Balance, Purchase, etc.
The IOS SDK, is not helpful, because I am making a Website, not a IOS App.

My Website Link: aiclastrocoin .com
Thanks

1 Like

thank you for all the details and more, if you could please report it here: Issues · MetaMask/metamask-mobile · GitHub