代码:
// 导入ethers包
import { ethers } from "ethers";
mainnet.g.alchemy.com/v2/oKmOQKbneVkxgHZfibs-iFhIlIAl6HDN';
import { config } from 'dotenv'
config()
let ALCHEMY_KEY_m = process.env.ALCHEMY_KEY_m || ''
const provider = new ethers.JsonRpcProvider(ALCHEMY_KEY_m)
const main = async () => {
// 查询vitalik的ETH余额
const balance = await provider.getBalance(`vitalik.eth`);
// 将余额输出在console
console.log(`ETH Balance of vitalik: ${ethers.formatEther(balance)} ETH`);}
main()
报错信息:
[Running] node "d:\sl\web3\study\code\WTF-Ethers\01_HelloVitalik\HelloVitalik.js"
JsonRpcProvider failed to detect network and cannot start up; retry in 1s (perhaps the URL is wrong or the node is not started)
node:internal/process/promises:288
triggerUncaughtException(err, true /* fromPromise */);
^
Error: read ECONNRESET
at TLSWrap.onStreamRead (node:internal/stream_base_commons:217:20) {
errno: -4077,
code: 'ECONNRESET',
syscall: 'read'
}
Node.js v18.17.1
访问了大概100次然后成功了一次 一直都在报这个错 检查url是正确,网络环境也是ok的 不知道到底是哪出问题了 之前用hardhat想verify合约也是显示timeout 难道是电脑的问题?