0

I use this in html src="https://cdn.jsdelivr.net/npm/web3@1.2.6/dist/web3.min.js" and when i call some functions i get error.Why this happend?Example i cannot call ethereum.enable() for allow metamask connection.I will show my js code and tell me how to fix it.Again i do not use node.js only html with linked mini.js for web3

      var web3 = new Web3('https://ropsten.infura.io/v3/148bee2b5da148a7b77a83f7504d00e7');


      var abi = [{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"getText","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"_text","type":"string"}],"name":"setText","outputs":[],"stateMutability":"nonpayable","type":"function"}]
      var adr="0x5aB715542BA0ccb7d6bCE4601aE437dC9dfF809c";
      var contractInstance = new web3.eth.Contract(abi, adr);

      //var account=web3.eth.defaultAccount=web3.accounts[0]  RETURNS UNDEFINED !!!!!
      console.log(web3.eth.accounts="0x1266f928B7964173434d3feB6DA2554b141920b8");

      contractInstance.methods.getText().call(function(err,res){
          if(!err){
              console.log(res);
          } else {
              console.log(err);
          }
      });
      contractInstance.methods.setText("bitsofcode").call();
      console.log(window.ethereum);
  • What error did you get? If you do not call ethereum.enable() it will not let you access to user's address. – Ismael Apr 2 at 14:35
  • I cannot write to contract. – Вања Хочак Apr 2 at 14:36
  • 1
    You are using .call() to modify a contract you have to used .send() instead. – Ismael Apr 2 at 14:49

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.