Last active
February 2, 2023 10:59
-
-
Save miguelmota/9735b62dc95b641ac2126dcb15b2d2fb to your computer and use it in GitHub Desktop.
JavaScript ethers fallback provider example
This file contains hidden or 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
const { providers } = require('ethers') | |
async function main() { | |
const url1 = 'https://optimism-mainnet.infura.io/v3/84842078b09946638c03157f83405213' | |
const url2 = 'https://mainnet.optimism.io' | |
const stallTimeout = 2 * 1000 | |
const options = { | |
timeout: 60 * 1000, | |
throttleLimit: 1 | |
} | |
const quorum = 1 | |
const provider1 = new providers.StaticJsonRpcProvider({url: url1, ...options}) | |
const provider2 = new providers.StaticJsonRpcProvider({url: url2, ...options}) | |
const provider = new providers.FallbackProvider([ | |
{ | |
provider: provider1, | |
priority: 2, | |
weight: 1, | |
stallTimeout | |
}, | |
{ | |
provider: provider2, | |
priority: 1, | |
weight: 1, | |
stallTimeout | |
} | |
], quorum) | |
const network = await provider.getNetwork() | |
console.log(network) | |
} | |
main().catch(console.error) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment