Setting up dapp environment - web3.ethereum.enable error

I’m getting the following console error when I load the index.html page:
Uncaught TypeError: Cannot read property ‘enable’ of undefined
at HTMLDocument. (main.js:4)
at e (jquery-3.4.1.min.js:2)
at t (jquery-3.4.1.min.js:2)

If I go down one directory from ‘dapp’, and start python web server there, I get the same error after navigating to ‘dapp/index.html’ in browser… but I can see that it has my custom main.js code
Where as if I start python web server in ‘dapp’ dir, the index.html page loads directly, and I get the same error, but when I view the main.js source, it is the skeleton code, and not the code I edited as per the instruction video.

My MetaMask extension/version is 4.11.1 in Brave
I NO LONGER have access to my wallet when I go back to the Main Ethereum Network…I get the error mesage "MetaMaskController - No HD Key Tree found

I restored metamask from seed phrase successfully, but haven’t figured out why ‘window.ethereum’ is undefined

Hi @freedomfflow

Can you share with us the first lines of your js file ?
When you are initializing web3 basically the first 30 lines of you js file ?

1 Like

Well, I have web3.min.js in my ‘dapp’ folder, which I believe I just pulled down with the index.hmtl file…

Its minified, so I copied a chunk here…

“use strict”;var _typeof2=“function”==typeof Symbol&&“symbol”==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&“function”==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?“symbol”:typeof t},_typeof=“function”==typeof Symbol&&“symbol”===_typeof2(Symbol.iterator)?function(t){return void 0===t?“undefined”:_typeof2(t)}:function(t){return t&&“function”==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?“symbol”:void 0===t?“undefined”:_typeof2(t)};!function(t){if(“object”===(“undefined”==typeof exports?“undefined”:_typeof(exports))&&“undefined”!=typeof module)module.exports=t();else if(“function”==typeof define&&define.amd)define([],t);else{(“undefined”!=typeof window?window:“undefined”!=typeof global?global:“undefined”!=typeof self?self:this).Web3=t()}}(function(){var define,module,exports;return function o(a,u,s){function c(e,t){if(!u[e]){if(!a[e]){var r=“function”==typeof require&&require;if(!t&&r)return r(e,!0);if(f)return f(e,!0);var n=new Error(“Cannot find module '”+e+"’");throw n.code=“MODULE_NOT_FOUND”,n}var i=u[e]={exports:{}};a[e][0].call(i.exports,function(t){return c(a[e][1][t]||t)},i,i.exports,o,a,u,s)}return u[e].exports}for(var f=“function”==typeof require&&require,t=0;t<s.length;t++)c(s[t]);return c}({1:[function(t,e,r){var n=r;n.bignum=t(“bn.js”),n.define=t("./asn1/api").define,n.base=t("./asn1/base"),n.constants=t("./asn1/constants"),n.decoders=t("./asn1/decoders"),n.encoders=t("./asn1/encoders")},{"./asn1/api":2,"./asn1/base":4,"./asn1/constants":8,"./asn1/decoders":10,"./asn1/encoders":13,“bn.js”:“BN”}],2:[function(t,e,r){var n=t("…/asn1"),i=t(“inherits”);function o(t,e){this.name=t,this.body=e,this.decoders={},this.encoders={}}r.define=function(t,e){return new o(t,e)},o.prototype._createNamed=function(e){var r;try{r=t(“vm”).runInThisContext("(function “+this.name+”(entity) {\n this._initNamed(entity);\n})")}catch(t){r=function(t){this._initNamed(t)}}return i(r,e),r.prototype._initNamed=function(t){e.call(this,t)},new r(this)},o.prototype._getDecoder=function(t){return t=t||“der”,this.decoders.hasOwnProperty(t)||(this.decoders[t]=this._createNamed(n.decoders[t])),this.decoders[t]},o.prototype.decode=function(t,e,r){return this._getDecoder(e).decode(t,r)},o.prototype._getEncoder=function(t){return t=t||“der”,this.encoders.hasOwnProperty(t)||(this.encoders[t]=this._createNamed(n.encoders[t])),this.encoders[t]},o.prototype.encode=function(t,e,r){return this._getEncoder(e).encode(t,r)}},{"…/asn1":1,inherits:101,vm:168}],3:[function(t,e,r){var n=t(“inherits”),i=t("…/base").Reporter,o=t(“buffer”).Buffer;function a(t,e){i.call(this,e),o.isBuffer(t)?(this.base=t,this.offset=0,this.length=t.length):this.error(“Input not Buffer”)}function u(t,e){if(Array.isArray(t))this.length=0,this.value=t.map(function(t){return t instanceof u||(t=new u(t,e)),this.length+=t.length,t},this);else if(“number”==typeof t){if(!(0<=t&&t<=255))return e.error(“non-byte EncoderBuffer value”);this.value=t,this.length=1}else if(“string”==typeof t)this.value=t,this.length=o.byteLength(t);else{if(!o.isBuffer(t))return e.error("Unsupported type: “+(void 0===t?“undefined”:_typeof(t)));this.value=t,this.length=t.length}}n(a,i),(r.DecoderBuffer=a).prototype.save=function(){return{offset:this.offset,reporter:i.prototype.save.call(this)}},a.prototype.restore=function(t){var e=new a(this.base);return e.offset=t.offset,e.length=this.offset,this.offset=t.offset,i.prototype.restore.call(this,t.reporter),e},a.prototype.isEmpty=function(){return this.offset===this.length},a.prototype.readUInt8=function(t){return this.offset+1<=this.length?this.base.readUInt8(this.offset++,!0):this.error(t||“DecoderBuffer overrun”)},a.prototype.skip=function(t,e){if(!(this.offset+t<=this.length))return this.error(e||“DecoderBuffer overrun”);var r=new a(this.base);return r._reporterState=this.reporterState,r.offset=this.offset,r.length=this.offset+t,this.offset+=t,r},a.prototype.raw=function(t){return this.base.slice(t?t.offset:this.offset,this.length)},(r.EncoderBuffer=u).prototype.join=function(e,r){return e||(e=new o(this.length)),r||(r=0),0===this.length||(Array.isArray(this.value)?this.value.forEach(function(t){t.join(e,r),r+=t.length}):(“number”==typeof this.value?e[r]=this.value:“string”==typeof this.value?e.write(this.value,r):o.isBuffer(this.value)&&this.value.copy(e,r),r+=this.length)),e}},{"…/base":4,buffer:47,inherits:101}],4:[function(t,e,r){var n=r;n.Reporter=t("./reporter").Reporter,n.DecoderBuffer=t("./buffer").DecoderBuffer,n.EncoderBuffer=t("./buffer").EncoderBuffer,n.Node=t("./node")},{"./buffer":3,"./node":5,"./reporter":6}],5:[function(t,e,r){var f=t("…/base").Reporter,n=t("…/base").EncoderBuffer,d=t("…/base").DecoderBuffer,i=t(“minimalistic-assert”),o=[“seq”,“seqof”,“set”,“setof”,“objid”,“bool”,“gentime”,“utctime”,"null”,“enum”,“int”,“objDesc”,“bitstr”,“bmpstr”,“charstr”,“genstr”,“graphstr”,“ia5str”,“iso646str”,“numstr”,“octstr”,“printstr”,“t61str”,“unistr”,“utf8str”,“videostr”],a=[“key”,“obj”,“use”,“optional”,“explicit”,“implicit”,“def”,“choice”,“any”,“contains”].concat(o);function u(t,e){var r={};(this._baseState=r).enc=t,r.parent=e||null,r.children=null,r

The code works with Chrome - It’s failing with Brave, even though I have shields down – so I guess I will continue with Chrome

Where you able to get it working? I had issues with ethereum.enable() initially as well. I was also using Brave, but my problem was with typescript as it’s a typed version of javascript and it wasn’t recognizing that window.ethereum was a valid property. Using web3.ethereum.enable() might actually have helped me LOL.

Gabba means showing where you create the web3 instance in your JS file. Like the following:

const Web3 = require('web3');
const web3 = new Web3(Web3.givenProvider);

FYI if you decide to install the web3 NPM package use the latest version 1.28. I had been using 1.25 and it had some typing errors related to BigNumberjs which were fixed between those versions.

1 Like

Yes it could :slight_smile: , thx @mayjer

2 Likes

It worked fine in Chrome. I have not tried upgrading the npm package yet and retrying with Brave. I am using ES6 syntax, so perhaps that was an issue? I didn’t check that out either. Once I saw it worked in Chrome I continued with that browser.
I will test it out in Brave again at some point soon.

Thanks for following up