Created
January 17, 2022 09:27
-
-
Save yann300/c51e4edab06c26ad4ec1ba6facca57ed to your computer and use it in GitHub Desktop.
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
// Right click on the script name and hit "Run" to execute | |
(async () => { | |
try { | |
const providerPlugin = { | |
sendAsync(payload, callback) { | |
window.remix.call('web3Provider', 'sendAsync', payload) | |
.then(result => callback(null, result)) | |
.catch(e => callback(e)) | |
} | |
} | |
let provider = new ethers.providers.Web3Provider(providerPlugin, "any"); | |
let network = await provider.getNetwork() | |
console.log('current network ' + network.chainId) | |
provider.on("network", async (newNetwork, oldNetwork) => { | |
console.log('new' + JSON.stringify(newNetwork)) | |
console.log('old' + JSON.stringify(oldNetwork)) | |
provider = new ethers.providers.Web3Provider(providerPlugin, "any"); | |
network = await provider.getNetwork() | |
}); | |
setInterval(() => { | |
console.log('current network ' + network.chainId) | |
}, 500) | |
} catch (e) { | |
console.log(e.message) | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment