-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Assign window.ethereum to givenProvider when available #3378
Conversation
This shouldn't break anything from my point of view.
If they provide the mentioned backward compatibility yes. Otherwise, would we have to update the |
Open discussion EIP-1193: ethereum/EIPs#2319 |
@nivida Thanks!
Dan Finlay says explicitly in Metamask 7710 that:
...so that base seems covered. Additional background: there's a Metamask blog post from Nov 6 advising developers to the follow this pattern wrt account access: window.addEventListener('load', async () => {
// Modern dapp browsers...
if (window.ethereum) {
window.web3 = new Web3(ethereum);
try {
// Request account access if needed
await ethereum.enable();
// Acccounts now exposed
web3.eth.sendTransaction({/* ... */});
} catch (error) {
// User denied account access...
}
}
// Legacy dapp browsers...
else if (window.web3) {
window.web3 = new Web3(web3.currentProvider);
// Acccounts always exposed
web3.eth.sendTransaction({/* ... */});
}
// Non-dapp browsers...
else {
console.log('Non-Ethereum browser detected. You should consider trying MetaMask!');
}
}); |
FYI: |
Note: this PR was originally put on hold because the mosaic repo instantiated Web3 for their test utilities as below: const web3 = new Web3(Web3.givenProvider || 'http://localhost:8545'); and called it like this: web3.currentProvider.send({
method: 'evm_mine',
jsonrpc: '2.0',
id: 1337,
},
(err) => {
if (err) {
return reject(err);
}
const newBlockHash = web3.eth.getBlock('latest').hash;
return resolve(newBlockHash);
});
}); However in Buidler,
I've just removed the mosaic fork's Web3 instantiation logic for unrelated reasons and the test now passes, but I think it might still be a case to be aware of. Buidler's |
Sounds good to me! |
great thanks, on second thought I'll do it in a follow-up PR to keep this one targeted for the intended issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Description
#3374
Metamask is rolling out their upgrade to an EIP-1193 compliant provider while preserving
web3.currentProvider.sendAsync
method for backwards compatibility.It looks like the original idea in
RequestManager/givenProvider
was to defer to the injected provider, but the standard's name for this changed at some point in the last 2 years and code here was not updated.Resources:
Questions:
Fixes #3374 (sort of...the issue makes a more general point about givenProvider side-effects)
Type of change
Checklist:
npm run dtslint
with success and extended the tests and types if necessary.npm run test:unit
with success and extended the tests if necessary.npm run build-all
and tested the resulting file/'s fromdist
folder in a browser.CHANGELOG.md
file in the root folder.