Hardhat:当我将合约部署到 sepolia 测试网络时,遇到错误:“无效的 URL 协议:URL 必须以 `http:` 或 `https:` 开头”

问题描述 投票:0回答:1

我在我的

hardhat.config.js 
中编码:

module.exports = {
  defaultNetwork: "hardhat",
  solidity: "0.8.24",
  networks: {
    sepolia: {
      url: "https://eth-sepolia.g.alchemy.com/v2/y4r3BgNFU-zhHGd8BWs-OhCMRR7ghpA2",
      accounts: [PRIVATE_KEY],
      chainId: 11155111,
    },
  }
};

我在终端中运行

npx hardhat run scripts/deploy.js --network sepolia
,但出现错误提示
Invalid URL protocol: the URL must start with "http:"or "https:"
然后我指向抛出错误的地方,并打印出
url

if (!/^https?:/.test(url.origin || url.protocol)) {
    console.log(url)
    throw new InvalidArgumentError('Invalid URL protocol: the URL must start with `http:` or `https:`.')
  }

这是打印出来的

url

URL {
  href: 'socks5://192.168.64.1:10808',
  origin: 'null',
  protocol: 'socks5:',
  username: '',
  password: '',
  host: '192.168.64.1:10808',
  hostname: '192.168.64.1',
  port: '10808',
  pathname: '',
  search: '',
  searchParams: URLSearchParams {},
  hash: ''
}

如何解决此错误?

node.js ethereum blockchain smartcontracts hardhat
1个回答
0
投票

我认为问题出在这里:

defaultNetwork: "hardhat"

应该是

sepolia

defaultNetwork: "sepolia"

另外,请确保导入此:

require("@nomiclabs/hardhat-ethers");
© www.soinside.com 2019 - 2024. All rights reserved.