Created
July 10, 2024 04:16
-
-
Save ardislu/14f805ccd63f78973cc84204d85d5384 to your computer and use it in GitHub Desktop.
The minimal JavaScript to select an EIP-6963 wallet as window.ethereum in the DevTools console for quick testing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// EIP-6963: Multi Injected Provider Discovery | |
// https://eips.ethereum.org/EIPS/eip-6963 | |
const wallets = []; | |
window.addEventListener('eip6963:announceProvider', e => wallets.push(e.detail)); | |
window.dispatchEvent(new Event('eip6963:requestProvider')); | |
console.table(wallets.map(w => w.info.name)); | |
console.log('Wallets have been collected in the \x1B[1;4mwallets\x1B[m object.'); | |
console.log('Basic example to set window.ethereum:\n \x1B[1mwindow.ethereum = wallets[0].provider;\x1B[m'); | |
console.log(`If you are using Rainbow, it's not possible to directly overwrite window.ethereum. Instead, you must use the new properties defined by Rainbow:\x1B[1m | |
window.rnbwWalletRouter.currentProvider = wallets[0].provider; // Will set window.ethereum to wallets[0].provider\x1B[m`); | |
// More info on Rainbow's new properties: | |
// https://github.com/rainbow-me/rainbow/blob/f8e1815c40a692b32a4450cedab812e5ee18f450/src/browser/inpage.ts#L89 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment