Skip to content

Instantly share code, notes, and snippets.

@yann300
Created January 17, 2022 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yann300/c51e4edab06c26ad4ec1ba6facca57ed to your computer and use it in GitHub Desktop.
Save yann300/c51e4edab06c26ad4ec1ba6facca57ed to your computer and use it in GitHub Desktop.
// 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