Skip to content

Commit

Permalink
Merge pull request #548 from oceanprotocol/feature/use_static_rpc_pro…
Browse files Browse the repository at this point in the history
…vider

use static rpc provider
  • Loading branch information
paulo-ocean authored Jul 24, 2024
2 parents 542a860 + af4619f commit 9c1c264
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/utils/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ export class Blockchain {
this.knownRPCs.push(...fallbackRPCs)
}
this.network = new ethers.Network(chainName, chainId)
this.provider = new ethers.JsonRpcProvider(rpc, this.network)
// this.provider = new ethers.JsonRpcProvider(rpc, this.network)
this.provider = new ethers.JsonRpcProvider(rpc, null, {
staticNetwork: ethers.Network.from(chainId)
})
this.registerForNetworkEvents()
// always use this signer, not simply provider.getSigner(0) for instance (as we do on many tests)
this.signer = new ethers.Wallet(process.env.PRIVATE_KEY, this.provider)
Expand All @@ -53,7 +56,7 @@ export class Blockchain {
}

public async isNetworkReady(): Promise<ConnectionStatus> {
if (this.networkAvailable || this.provider.ready) {
if (this.networkAvailable && this.provider.ready) {
return { ready: true }
}
return await this.detectNetwork()
Expand All @@ -70,11 +73,12 @@ export class Blockchain {
CORE_LOGGER.error(`Unable to detect provider network: (TIMEOUT)`)
resolve({ ready: false, error: 'TIMEOUT' })
}, 3000)

this.provider
._detectNetwork()
.then((network) => {
.getBlock('latest')
.then((block) => {
clearTimeout(timeout)
resolve({ ready: network instanceof Network })
resolve({ ready: block.hash !== null })
})
.catch((err) => {
CORE_LOGGER.error(`Unable to detect provider network: ${err.message}`)
Expand Down

0 comments on commit 9c1c264

Please sign in to comment.