Closed olegabr closed 3 years ago
@olegabr hello/ I'm not aware of anything changing about the injection logic recently. When did you start to see the new behavior? Can you show where you're adding and calling your custom web3?
Thank you for your answer @kumavis, This behaviour is not new. MM always injected it's web3.js version in a page. It was just not a problem for me until recently.
my custom web3 code:
if ("undefined" !== typeof window.epg.web3Endpoint) {
window.epg.web3 = new Web3(new Web3.providers.HttpProvider(window.epg.web3Endpoint));
}
window.epg.web3Endpoint
- is an infura.io URL
In PHP code my web3.js copy is loaded by
wp_register_script(
'web3', $base_url . "/js/web3{$min}.js", array('jquery'), '0.20.6'
);
and later
wp_enqueue_script(
'wooetherc20paymentgateway',
$base_url . "/js/ether-and-erc20-tokens-woocommerce-payment-gateway{$min}.js",
array('jquery', 'bootstrap.wizard', 'web3', 'jquery.qrcode'),
'2.6.5'
);
The MM web3 object is obtained this way:
window.ethereum.enable().then(function(accounts) {
var injectedProvider = window.ethereum;
window.epg.web3metamask = new Web3(injectedProvider);
}
And tx is sent by
window.epg.web3metamask.eth.sendTransaction(/* ... */)
After writing all this I understood that my web3.js version is used for my window.epg.web3
object and MM web3.js version is used for the window.epg.web3metamask
object, and this is a right behavior.
If you have no ideas how it can be made better, just close this issue please.
I've checked in a debugger and I was wrong. Even when contract method on my own created web3 object is called, the MM version of web3.js is actually used, not the one I've loaded on my page.
I've found a very ugly but workable workaround for my problem: https://github.com/INFURA/infura/issues/189#issuecomment-535937835 So, this isue is not urgent for me anymore. Feel free to close it if you see no way to fix it in a reasonable time.
Thanks for the report!
I'll close this now, as we will no longer be injecting web3 at all as of v9.0.0 (See here: #7163), which will be released quite soon.
Describe the bug
MetaMask injects it's own version of web3.js which replaces the one used in custom code. It makes web3.js patching impossible. More details here: https://github.com/INFURA/infura/issues/189
To Reproduce Steps to reproduce the behavior:
Expected behavior The web3.js version loaded on the page should be used by user code. The MetaMask loaded code should not be used instead.
Screenshots![Screenshot from 2019-09-24 17-49-38](https://user-images.githubusercontent.com/2850808/65506233-54a58c00-def5-11e9-9139-b65fefcd5308.png)
Browser details (please complete the following information):
Additional context
my web3.js 0.20.7 branch patch (trying to fix the https://github.com/INFURA/infura/issues/189):