Dom*_*nik 8 config typescript ethereum hardhat
我正在尝试在 Goerli 上部署合约,但我不断收到错误Error HH100: Network goerli doesn't exist
这是我的hardhat.config.ts
require("dotenv").config();
import { task } from 'hardhat/config';
import '@nomiclabs/hardhat-waffle';
import '@typechain/hardhat'
import '@nomiclabs/hardhat-ethers';
import { HardhatUserConfig } from "hardhat/config";
const PrivateKey = "b427...";
const config: HardhatUserConfig = {
solidity: {
version: '0.8.0',
},
networks: {
goerli: {
chainId: 5,
url: "https://goerli.infura.io/v3/309820d3955640ec9cda472d998479ef",
accounts: [PrivateKey],
},
},
};
// This is a sample Hardhat task. To learn how to create your own go to
// https://hardhat.org/guides/create-task.html
task('accounts', 'Prints the list of accounts', async (taskArgs, hre) => {
const accounts = await hre.ethers.getSigners();
for (const account of accounts) {
console.log(account.address);
}
});
// You need to export an object to set up your config
// Go to https://hardhat.org/config/ to learn more
export default {
solidity: '0.8.0',
};
Run Code Online (Sandbox Code Playgroud)
谢谢!
我不知道我应该添加什么,但请询问,我会发布更多信息。
小智 2
我前两天就出现这个错误。我可以通过这一步解决它。
npm 初始化
npm install --save-dev Hardhat @nomiclabs/hardhat-ethers "ethers@^5.0.0"
创建一个空的hardhat.config.js
现在您的项目是安装安全帽。并创建将备份文件夹中的所有文件夹和 Solidity 代码复制到项目文件夹中,但如果您有工件和缓存文件夹,请不要复制它。
并在 Hardhar.config.js 文件中将此代码粘贴到顶部。
require('@nomiclabs/hardhat-ethers')
const API_URL = "Your testnet rpc link";
const PRIVATE_KEY = "Your Private Accout address"
const PUBLIC_KEY = "Your Account Address";
Run Code Online (Sandbox Code Playgroud)
并在此处的 module.module 导出代码中。
module.exports = {
solidity: "0.8.0",
defaultNetwork: "yourtestnetname",
networks: {
hardhat:{},
yourtestnetname:{
url: API_URL,
accounts: [`0x${PRIVATE_KEY}`]
}
}
};
Run Code Online (Sandbox Code Playgroud)
检查 0x${}
以确保它在您的 PRIVATE_KEY 中。然后使用这个命令
npx 安全帽编译
如果编译成功,文件夹工件和缓存将在您的项目中生成并生成智能合约代码。并将代码复制到备份的deploy.js 文件中。
现在使用此命令部署.js 文件
npx Hardhat 运行脚本/deploy.js --network yournamenetwork
如果编译成功你的终端将显示你的合约地址
您可以在此处查看此视频教程。
或例如我的 git Repo smart_contract 文件夹
归档时间: |
|
查看次数: |
16728 次 |
最近记录: |