I have been trying to inject metamask into my site using web3. I have called web3 in my site as below and started the site using local server(VS Code extension which gives me port:5500)

    window.addEventListener('load', async () => {
      if (window.ethereum) {
        window.web3 = new Web3(ethereum);
        try {
          await ethereum.enable();
        } catch (err) {
          $('#status').html('User denied account access', err)
      } else if (window.web3) {
        window.web3 = new Web3(web3.currentProvider)
      } else {
        $('#status').html('No Metamask (or other Web3 Provider) installed')

Later I am calling my contracts as below and I am facing troubles.

pay() is a function that happens with a button click in my HTML. It needs payout() function to be called from my Smart contract so initially I defined it as you can see below in 1st line.

    window.contract = new window.web3.eth.Contract(
           [  abi    ] , '0xC4AfE8504a711bE2D5E25b45eb72fC3f0924aB21');
        function pay() {

            var paymentAddress = document.getElementById("address").value;
            var val = document.getElementById("weight").value;
            var type= document.getElementById("category").value;

            contract.methods.payout.sendTransaction( paymentAddress ,val,type )

I am getting the following error

MetaMask no longer injects web3

Uncaught TypeError: window.web3.eth is undefined

I have tried lot of ways but couldn't go further please help me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.