Search code examples
ethereumsolidityweb3js

I am getting trouble calling the contract methods in front end


I want to call my contract from the browser itself so I have used Metamask for that and it works seamlessly but the thing I don't want to use Metamask because of Metamask cannot be used in phone

I have used metamask and it works I have used trufflehdwallet in backend and it works I have used testrpc network and it also works

if (window.ethereum) {
        window.web3 = new Web3(ethereum);
        try {
            // Request account access if needed
            await ethereum.enable();

            web3.eth.getAccounts(function (err, accounts) {
                if (!err) {
                    get_contract();
                }
            })

        } catch (error) {
            // User denied account access...
        }
    }
    // Legacy dapp browsers...
    else if (window.web3) {
        window.web3 = new Web3(web3.currentProvider);

        web3.eth.getAccounts(function (err, accounts) {
            if (!err) {
                get_contract();
            }
        })
    }
    // Non-dapp browsers...
    else {
        console.log('Non-Ethereum browser detected. You should consider installing MetaMask !');
    }

I want something like this

web3 = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io/v3/24b7104373aa4038a2d0b64d9d60bd85"));

Solution

  • I think your question is different than the title, actually. From your question, I understood that you want to use your web dapp on your smartphone.

    Well, if that is the question, I have a few options for you. First of all, if you are using the mainnet, you have a few mobile apps, such as GnosisSafe or TrustWallet. If you are using testnets, there's a new wallet named Portis, that allows you to connect to public testnets. Honestly, I don't recommend you to test local networks, as it is a web dapp and you can test on your laptop with metamask.

    So, my final hint would be web3connect. This allows the user to choose his wallet.