解聚协定>>时出错 错误:无法检测到网络(事件 = "noNetwork" ,代码 = NETWORK_ERROR,版本 = 提供程序/5.7.2)



im正在尝试使用npx hardhat run scripts/deploy.js来depoy我的合同--network goerli和我一直在处理上面的错误//这是错误

omota@DESKTOP-3T9OR5N MINGW32 ~/web3-projects/tinder-blockchain/smart-contract (main)
$ npx hardhat run scripts/deploy.js --network goerli
Compiled 1 Solidity file successfully
error in depolying contract >> Error: could not detect network (event="noNetwork", code=NETWORK_ERROR, version=providers/5.7.2)
at Logger.makeError (C:Usersomotaweb3-projectstinder-blockchainsmart-contractnode_modules@ethersprojectloggersrc.tsindex.ts:269:28)
at Logger.throwError (C:Usersomotaweb3-projectstinder-blockchainsmart-contractnode_modules@ethersprojectloggersrc.tsindex.ts:281:20)
at EthersProviderWrapper.<anonymous> (C:Usersomotaweb3-projectstinder-blockchainsmart-contractnode_modules@ethersprojectproviderssrc.tsjson-rpc-provider.ts:483:23)
at step (C:Usersomotaweb3-projectstinder-blockchainsmart-contractnode_modules@ethersprojectproviderslibjson-rpc-provider.js:48:23)
at Object.throw (C:Usersomotaweb3-projectstinder-blockchainsmart-contractnode_modules@ethersprojectproviderslibjson-rpc-provider.js:29:53)
at rejected (C:Usersomotaweb3-projectstinder-blockchainsmart-contractnode_modules@ethersprojectproviderslibjson-rpc-provider.js:21:65)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
reason: 'could not detect network',
code: 'NETWORK_ERROR',
event: 'noNetwork'
}

//这是我的depoy.js文件

const { ethers } = require('hardhat')
const main = async () => {
const tinderFactory = await ethers.getContractFactory('TinderERC721')
const tinderContract = await tinderFactory.deploy()
console.log('TINDER CONTRACT ADDRESS:', tinderContract.address)
};
main()
.then(() => process.exit(0))
.catch(error => {
console.log('error in depolying contract >>', error);
process.exit(1);
})

//这是我的硬帽——fig.js

require("@nomicfoundation/hardhat-toolbox");
require('dotenv').config({path: '.env'})
const ALCHEMY_API_URL = process.env.ALCHEMY_API_URL
const GOERLI_PRIVATE_KEY = process.env.GOERLI_PRIVATE_KEY
/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
defaultNetwork: 'goerli',
networks: {
goerli: {
url: ALCHEMY_API_URL,
accounts: [`0x${GOERLI_PRIVATE_KEY}`],
},
},
solidity: '0.8.17',
}

如有任何帮助,将不胜感激

我已经做了我能做的任何事情,但仍然是一样的

我也有同样的错误。由于您使用.env存储私钥,因此如果值存储为:"https://eth-goerli.alchemyapi.io/v2/${ALCHEMY_API_KEY}";在.env文件本身中,将其更改为完整链接:"https://eth-goerli.alchemyapi.io/v2/xxxxxxxxxxxxxxxxxxxxxxx">

我也得到了一个";私钥太长";错误,因为在.env文件中使用分号分隔语句。。。希望这能有所帮助!

也许您在ALCHEMY_API_URL方面有一些问题。它应该采用以下形式:

https://eth-goerli.alchemyapi.io/v2/${ALCHEMY_API_KEY}

或者可以肯定的是,您可以使用公共RPC节点:

https://goerli.infura.io/v3/         //default on metamask
https://rpc.ankr.com/eth_goerli      //I tried and it worked
https://eth-goerli.public.blastapi.io
https://rpc.goerli.mudit.blog

相关内容