-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[hardhat-ethers] Printing the provider always seems to indicate that it's pointing to localhost #1138
Comments
Copying my comment from #1798 in case someone lands here. You can use You can also use |
@fvictorio commented on August 20, 2021 6:55 PM:
Also noting #2309 for reference.
Yes, surely there should be a single way to get the URL regardless of whether it's Hardhat network or something else. Also, referencing I suspect |
But the Hardhat network doesn't have a URL. It's an in-process network, so there's no networking involved.
I think the types of the networks behave like this: hre.networks.hardhat // HardhatNetworkConfig, doesn't have a URL
hre.networks["something"] // HttpNetworkConfig, has a URL
const someNetwork = hre.networks[stringVariable] // HardhatNetworkConfig | HttpNetworkConfig
// you should be able to narrow the type
if ('url' in someNetwork) {
// someNetwork: HttpNetworkConfig
} else {
// someNetwork: HardhatNetworkConfig
} I haven't checked that this is correct in an actual typescript project, so take it with a grain of salt. |
Just checked - you were indeed correct, and the Thanks! |
If you
console.log
ethers.provider
, it prints alocalhost
url. This is confusing and many times incorrect. We should try to improve this by setting the url to something else. Maybe a message explaining that the value is bogus.Search terms: localhost:8545, connection, url, ethers.
The text was updated successfully, but these errors were encountered: