Open wbt opened 4 years ago
Yep! Should definitely not have that warning. Thanks for the issue @wbt!
I don't think that this should cause a problem once MetaMask stops injecting web3 though the message is annoying. I believe this message comes from Truffle's own web3 dependency which checks to see if there is a global web3 around. In the future I think this will not find a global web3 and not use it.
It looks like this should be more of an issue for Drizzle I would think?
Why does Truffle check to see if there is a global web3 around just when loading the Javascript file? It should not be doing anything at that time.
@truffle/contract
has a dependency on web3
. At some point web3
checks to see if there is a global provider. If you follow the stacktrace in the console it will lead you to web3
code.
Looking into this, we don't believe there will be an issue on the Truffle side from removing the warning. There may be problems from the Drizzle side of things. Do you have any thoughts @cds-amal?
I think the best solution to this is that if Web3 is looking for a global provider, that is what should be changed...loading a library module should just define things and not do more.
Issue
When loading @truffle/contract for browser usage, the following warning is triggered:
Steps to Reproduce
Create the following HTML file:
Set up a local web server (e.g. with Node/Express) to serve this file and /js/truffle-contract.js. Access the file in a Metamask-enabled browser and open the console.
Expected Behavior
It should be possible to load this Javascript into memory without doing anything, so that the TruffleContract object is available, but there is no MetaMask warning unless/until the script attempts to access an injected global web3. This permits truffle-contract to be loaded in parallel with other scripts in initial page-load, instead of requiring waiting until after initializing web3 with a provider.
Actual Results
TruffleContract is trying to use the globally injected web3 object at the time of loading, triggering that warning.
Environment