0

i have a few codes that works fine on chrome desktop but dosent work with metamask mobile im using web3.js 1.2.7 here is code for connecting to wallet :

import Web3 from 'web3';
var web3 = new Web3(window.ethereum);
 ConnectedAccount = await window.ethereum.request({
        "method": "eth_requestAccounts",
        "params": []
    });
const MaticTokenContract =  new web3.eth.Contract(MaticABI, MaticContractAddress , {from : ConnectedAccount})

on the desktop its work fine but on the metamask mobile dosent work also i have deployed contract that functions works fine on desktop but on mobile its not working im trying to get approve token and then call Buy function

    const PreSaleContract = new web3.eth.Contract(ABI , PreSaleContractAddress );
 const Token = new web3.eth.Contract(TokenABI , TokenAddress );
        await Token.methods.approve(PreSaleContractAddress, 369369369000000).send({from: ConnectedAccount});

on desktop approval works fine but on mobile when clicking on approval button its not working , its should open metamask popup and ask for approval but does noting

Update 1 i have switched to ether.js v5 but again in mobile dosent work in desktop its work fine i have create matic token instance and trying to get wallet address balance and token decimals in dekstop its ok and working fine but in metamask mobile no reaction

1 Answer 1

0

Not sure if this is your answer, but did you try checking for window.web3? Do an if/else by checking for window.ethereum and if that's not true, check for window.web3

I haven't worked with the web3 library in over a year, so I am unsure if this will solve your problem. It may be possible that the mobile version hasn't updated to the window.ethereum way of doing it yet.

4
  • hi i have checked window.web its work just like window.ethereum cant call any contract functions(tried matic , my token and my contract) but calls dosent send Commented Apr 18 at 2:34
  • i have edited my question please read it , thanks Commented Apr 18 at 4:28
  • Have you read the metamask docs? I don't see you using requestPermission but also, methods should be using asynchronous methods. Again, read current docs or find metamask specific channel to ask. Commented Apr 18 at 7:15
  • you try using the metamask sdk? Just noticed there's a sdk for nodejs. Give that a try, may have better luck. Not sure if it handles other wallets though. May need to do checks for either or Commented Apr 21 at 0:53

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.