1

Iam connecting to metamask and sending transactions(trc20) using my desktop web browser. Its working perfectly. But in mobile, metamask browser or native android browsers is not detecting metamask or any window.ethereum object. This is the basic code Im using,

    if (typeof window.ethereum !== 'undefined') {
        console.log('Wallet is installed!');
    } else {
        alert('Metamask Wallet is not installed!');
        return
    }

I'm getting wallet not installed message.

I tried many other ways from various other threads and still not able to interact with metamask.

I also checked the deeplinking part but no help.

When I initialise like,

const web3 = new Web3(window.ethereum);

I'm able to do,

const value = web3.utils.toWei(amount, 'ether')

It gives me converted value.

But still window.ethereum is showing as undefined

Any help is appreciated :)

4
  • Depending on where you're trying to use window.ethereum, you might be calling it before it is actually injected. Have a look at the docs (docs.metamask.io/guide/…) and try to check for it using the async snippet through detectEthereumProvider()
    – razgraf
    Commented Apr 27, 2022 at 13:47
  • Already tried that. I waited for the object to get injected(as mentioned in docs). But still the same issue persists
    – PrG
    Commented Apr 28, 2022 at 11:06
  • @razgraf Can you tell me how to implement metamask interaction with web3js on metamask mobile browser ( browser which is inbuilt in metamask ). I tried waiting till it is injected as mentioned in docs.
    – PrG
    Commented May 5, 2022 at 7:10
  • If the browser extension manages to connect to your website I don't see why the mobile metamask browser would have a problem with it. I suggest trying to debug using the example code given in those docs (docs.metamask.io/guide/…). An alternative if you don't figure it out is to rely on an already existing implementation, something like useDapp.io
    – razgraf
    Commented May 5, 2022 at 11:47

1 Answer 1

1

when you have the metamask extension installed in your browser, window.ethereum will return a valid object, but in mobile browsers, you can't install extensions. The issue is not your code, it's how the code works and it works with browsers that have the extension installed such as your desktop browsers, e.g chrome, mozilla, e.t.c.

4
  • So you are telling that it wont work in mobile browsers or metamask mobile app built in browser???
    – PrG
    Commented Apr 28, 2022 at 11:07
  • mobile browsers Commented May 1, 2022 at 8:13
  • Can you tell me how to implement metamask interaction with web3js on metamask mobile browser ( browser which is inbuilt in metamask )
    – PrG
    Commented May 4, 2022 at 5:51
  • const web3 = new Web3(Web3.givenProvider) Commented May 5, 2022 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.