MetaMask / MetaMask/metamask-mobile
USDT Balance Not Showing in Metamask in-built Browser on Mobile Devices
- Dominant language
- TypeScript
- Stars
- 3k
- Forks
- 1.7k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 669
Description
### What is this about?
My Web-3 Website Link: https://aiclastrocoin.com/presale
I am developing a Crypto website using JavaScript. I have a ‘Wallet Connect’ button to connect to various wallets, like, MetaMask, Trust Wallet, etc. On my Desktop/ Laptop, I am connecting to Browser extensions for all wallets, and my code is working fine, able to connect to wallet extensions, see account balances, and make payments. But in Metamask, on Mobile devices, I am having issues. I open my website in Metamask Browser in a Mobile device. **I am able to connect but unable to see account balances, nor can I make any payment of USDT using MetaMask. It is showing an 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”}}}”_**. Everything is working fine for BNB Payment in Metamask mobile app. And no Issues in other Wallet's Mobile app.
I would appreciate any help for this issue.
### Scenario
- A User loads our crypto website using a Non-Web3 Browser, like Chrome on his mobile device.
- User clicks the 'Connect Wallet' button. The different wallet options appear. User clicks 'Metamask'.
- After entering the password, the in-built Metamask browser opens up, and the website is visible.
- User clicks 'Connect Wallet' inside Metamask browser. the wallet gets connected.
- The Crypto Network is changed to BSC (Binance Smart Chain).
- The BNB Balance of the account is shown correctly, but the USDT balance shows a JSON-RPC error.
- Our website works fine on desktops/ Laptops correctly for various wallets and browsers like Chrome, Edge, and Brave.
- Other Wallets (like, Coinbase, and Trust Wallet) are showing USDT and BNB balances correctly on Mobile devices (including tablets).
### Design
_No response_
### Technical Details
I am currently testing for Android, and using Binance Smart Chain Network.
The Endpoint URL is: ‘bsc-dataseed.binance.org/’
My BNB Balance is being Fetched, but not USDT.
The Same Code is working for the Trust Wallet App on Mobile devices.
My Metmask Connection and USDT Balance Retrieval 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');
});
}
```
### Threat Modeling Framework
_No response_
### Acceptance Criteria
USDT Balance shows correctly, in **Metamask in-Built Browser**, on Mobile Devices
### References
Screenshot:

Contributor guide
Research direction
No repository file or test is identified. Start by reproducing the report in the MetaMask mobile in-built browser on Android with BSC, then inspect the wallet_switchEthereumChain and balanceOf calls shown in the report. Done means the USDT balance retrieval and payment flow work there without the reported JSON-RPC revert.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react-native, typescript
- Domain
- blockchain, mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 18/100