ethers.js icon indicating copy to clipboard operation
ethers.js copied to clipboard

Unable to immediately read the chainId of the network

Open hairyf opened this issue 1 year ago • 1 comments

Ethers Version

6.*

Search Terms

No response

Describe the Problem

Provided Network for JsonRpcProvider, but was unable to read the chainId of the network. In other environments, I am unable to determine which chain this provider belongs to

const network = new Network('https:...', 44)
const provider = new JsonRpcProvider('https...', network)
// error: ethers network is not available yet
provider._network.chainId

when specifying the network, _network should be readable, It shouldn't have to wait for a while to obtain it

Code Snippet

No response

Contract ABI

No response

Errors

No response

Environment

No response

Environment (Other)

No response

hairyf avatar Jul 26 '24 04:07 hairyf

To access the _network synchronously, I think you need to configure it as a static network; try new JsonRpcProvider(url, network, { staticNetwork: true }).

ricmoo avatar Jul 26 '24 05:07 ricmoo

I've confirmed that this works as expected; if the network is configured as static the ._network is immediately available.

Let me know if you have any questions about this. :)

ricmoo avatar Aug 31 '24 01:08 ricmoo