我在VScode中设置了Hardhat,并设置了所需的依赖项,运行了一个带有Metamask的Alchemy节点。我已经尝试了我在网上找到的大多数故障排除方法,并阅读了大多数文档,但我仍然迷失了方向。你需要什么信息我都能提供。什么都行。非常感谢。我是个新手,所以请配合我。
- 我收到的错误如下:**
npx hardhat node
Error HH604: Error running JSON-RPC server: Must be authenticated!
- Hardhat. config. ts**
import "@typechain/hardhat";
import "@nomiclabs/hardhat-ethers";
import "@nomiclabs/hardhat-waffle";
import "@nomiclabs/hardhat-etherscan";
import "hardhat-gas-reporter";
import "solidity-coverage";
import "@openzeppelin/hardhat-upgrades";
import "hardhat-deploy";
import { resolve } from "path";
import { config as dotenvConfig } from "dotenv";
import { HardhatUserConfig } from "hardhat/config";
import { NetworkUserConfig } from "hardhat/types";
dotenvConfig({ path: resolve(__dirname, "./.env") });
const chainIds = {
goerli: 5,
hardhat: 1337,
kovan: 42,
mainnet: 1,
rinkeby: 4,
ropsten: 3,
};
// Ensure that we have all the environment variables we need.
const privateKey = process.env.PRIVATE_KEY;
// Make sure node is setup on Alchemy website
const alchemyApiKey = process.env.ALCHEMY_API_KEY;
function getChainConfig(network: keyof typeof chainIds): NetworkUserConfig {
const url = `https://eth-${network}.alchemyapi.io/v2/${alchemyApiKey}`;
return {
accounts: [`${privateKey}`],
chainId: chainIds[network],
url,
};
}
const config: HardhatUserConfig = {
defaultNetwork: "hardhat",
gasReporter: {
currency: "USD",
enabled: process.env.REPORT_GAS ? true : false,
excludeContracts: [],
src: "./contracts",
},
networks: {
hardhat: {
forking: {
url: `https://eth-mainnet.alchemyapi.io/v2/${alchemyApiKey}`,
},
chainId: chainIds.hardhat,
},
// Uncomment for testing. Commented due to CI issues
// mainnet: getChainConfig("mainnet"),
// rinkeby: getChainConfig("rinkeby"),
// ropsten: getChainConfig("ropsten"),
},
paths: {
artifacts: "./artifacts",
cache: "./cache",
sources: "./contracts",
tests: "./test",
deploy: "./scripts/deploy",
deployments: "./deployments",
},
solidity: {
compilers: [
{
version: "0.8.10",
settings: {
metadata: {
bytecodeHash: "none",
},
optimizer: {
enabled: true,
runs: 800,
},
},
},
{
version: "0.8.10",
settings: {
metadata: {
bytecodeHash: "none",
},
optimizer: {
enabled: true,
runs: 800,
},
},
},
{
version: "0.7.5",
settings: {
metadata: {
bytecodeHash: "none",
},
optimizer: {
enabled: true,
runs: 800,
},
},
},
{
version: "0.5.16",
},
{
version: "0.8.10",
settings: {
metadata: {
bytecodeHash: "none",
},
optimizer: {
enabled: true,
runs: 800,
},
},
},
],
settings: {
outputSelection: {
"*": {
"*": ["storageLayout"],
},
},
},
},
namedAccounts: {
deployer: {
default: 0,
},
daoMultisig: {
// mainnet
1: "HIDDEN",
},
},
typechain: {
outDir: "types",
target: "ethers-v5",
},
etherscan: {
apiKey: process.env.ETHERSCAN_API_KEY,
},
mocha: {
timeout: 1000000,
},
};
export default config;
2条答案
按热度按时间ffx8fchx1#
此错误通常在Alchemy URL不正确时显示。如果有帮助,您可以尝试验证密钥一次。
drnojrws2#
我确保Alchemy的URL是正确的。将API密钥添加到项目后,您还可以获取Alchemy URL(在Alchemy Jmeter 板中找到)并将其添加到项目中。