所以我尝试运行这个命令(npxhardhatcompile)并且vscode告诉我
警告:您当前使用的是 Node.js v19.8.1,Hardhat 不支持该版本。这可能会导致意外的行为。请参阅https://hardhat.org/nodejs-versions .Error HH8:您的配置文件中存在一个或多个错误:
要了解有关 Hardhat 配置的更多信息,请访问 https://hardhat.org/config/
有关更多信息,请访问 https://hardhat.org/HH8 或使用 --show-stack-traces 运行 Hardhat
当我查看该网址时,我了解到今年的hardhat正在使用node.js 21,因此我尝试了(nvm-windows、npm install -g nodist、nvm install 21),但仍然收到类似警告(nvm:Le)术语“nvm”不是 reconnu comme nom d'applet de commande,
函数,脚本或可执行程序的文件。验证
L'orthographe du nom, ou si un chemin d'accès Existe, verifiez que le
chemin d'accès est Correct et réessayez。)
知道我应该做什么
您收到的警告和错误消息表明两个不同的问题:
Node.js 版本警告:
帐户无效错误:
解决这些问题:
Node.js 版本:
无效帐户:
hardhat.config.js
或 hardhat.config.ts
)并找到孟买网络的配置。您想要通过为孟买网络提供有效的私钥来修复无效帐户错误。
使用新私钥更新您的 Hardhat 配置文件(
hardhat.config.js
或 hardhat.config.ts
):
module.exports = {
networks: {
mumbai: {
url: 'https://rpc-mumbai.maticvigil.com',
accounts: [yourValidPrivateKey],
},
},
// other configuration options...
};
.env
文件并像这样设置你的私钥 MUMBAI_PRIVATE_KEY="yourPrivateKeyHere"
或者你这样做⬇️:为您的私钥设置环境变量。打开终端并运行:
export MUMBAI_PRIVATE_KEY="yourPrivateKeyHere"
或者,您可以使用像
dotenv
这样的工具来管理环境变量。
更新您的 Hardhat 配置文件以从环境变量中读取私钥:
require('dotenv').config();
module.exports = {
networks: {
mumbai: {
url: 'https://rpc-mumbai.maticvigil.com',
accounts: [process.env.MUMBAI_PRIVATE_KEY],
},
},
// other configuration options...
};
进行这些更改后,尝试再次运行
npx hardhat compile
。如果您遇到其他问题,请仔细检查您的 Hardhat 配置并进行必要的调整。