I am trying to connect a Dapp to Metamask. My code works, but not on mobile (using Metamasks built-in browser). This is the code:
<script type="text/javascript">
if (window.ethereum) {
handleEthereum();
} else {
window.addEventListener('ethereum#initialized', handleEthereum, {
once: true,
});
// If the event is not dispatched by the end of the timeout,
// the user probably doesn't have MetaMask installed.
setTimeout(handleEthereum, 3000); // 3 seconds
}
function handleEthereum() {
const { ethereum } = window;
if (ethereum && ethereum.isMetaMask) {
console.log('Ethereum successfully detected!');
} else {
console.log('Please install MetaMask!');
}
}
</script>
I tried waiting 15 seconds instead of 3, but it didn't work anyways. I am using Webflow, and adding JavaScript custom code to it. I don't know if that could be the problem.
I did it in the following way
const base64image = 'imagen';
ethereum.request({
method: 'wallet_watchAsset',
params: {
type: 'ERC20',
options: {
address: wallet,
symbol: simbolo,
decimals: 18,
image: base64image,
},
},
});
This part was for the browser, for the mobile I have not been able to solve it.