简体   繁体   English

Ropsten Networks 未定义

[英]Ropsten Networks is Undefined

I'm trying to connect the Ropsten TestNet on Metamask to my project.我正在尝试将 Metamask 上的 Ropsten TestNet 连接到我的项目。 But I have a problem that I haven't been able to solve for days.但是我有一个问题,我已经好几天没能解决了。 I made a definition as follows on the page I want to redirect.我在要重定向的页面上做了如下定义。

And I wanted it to give me a message when I wanted it to be an error.当我希望它是一个错误时,我希望它给我一个信息。 I am getting exactly that error right now.我现在得到的正是那个错误。 'Make sure you are on the corrent network. '确保你在正确的网络上。 Set the network to Ropsten Test Network'将网络设置为 Ropsten 测试网络'

publicdashboard.jsx publicdashboard.jsx

    useEffect(() => {
        const init = async () => {
            try {
                const web3 = await getWeb3();
                const accounts = await web3.eth.getAccounts();
                const networkId = await web3.eth.net.getId();
                const deployedNetwork = Project.networks[networkId];
                if(deployedNetwork === undefined)
                    throw new Error('Make sure you are on the corrent network. Set the network to Ropsten Test Network');
                const contract = new web3.eth.Contract(
                    Project.abi,
                    deployedNetwork.address,
                );
                setWeb3(web3);
                setAccounts(accounts);
                setContract(contract);
            } catch (error) {
                window.alert(error);
                history.push("/dashboard");
            }
        }
        init();
        if (isReady()) {
            window.ethereum.on('accountsChanged', accounts => {
                setAccounts(accounts);
            });
        }
    }, [history]);

And this is my truffle-config.js file.这是我的 truffle-config.js 文件。 Everything seems normal.一切似乎都很正常。 I don't understand why it is not connecting.我不明白为什么它没有连接。 Can you help me with this?你能帮我解决这个问题吗?

const path = require("path");

const HDWalletProvider = require('@truffle/hdwallet-provider');

const fs = require('fs');
const mnemonic = fs.readFileSync(".secret").toString().trim();

module.exports = {
  
  contracts_build_directory: path.join(__dirname, "src/contracts"),
  networks: {
    ropsten: {
      provider: () => new HDWalletProvider(mnemonic, 'https://ropsten.infura.io/v3/08ac778579d74dbaa8d2e3d02e5c0092'),
      network_id: 3, // Ropsten's id
      gas: 5500000, // Ropsten has a lower block limit than mainnet
      confirmations: 2, // # of confs to wait between deployments. (default: 0)
      timeoutBlocks: 200, // # of blocks before a deployment times out  (minimum/default: 50)
      skipDryRun: false // Skip dry run before migrations? (default: false for public nets )
    },
  },

  mocha: {
    // timeout: 100000
  },

  compilers: {
    solc: {
      //version: "0.8.13",      // Fetch exact version from solc-bin (default: truffle's version)
      // docker: true,        // Use "0.5.1" you've installed locally with docker (default: false)
      // settings: {          // See the solidity docs for advice about optimization and evmVersion
      //  optimizer: {
      //    enabled: false,
      //    runs: 200
      //  },
      //  evmVersion: "byzantium"
      // }
    }
  },

 }
};

And also I wrote the terminal this code "truffle migrate --network ropsten".我还在终端上写了这段代码“truffle migrate --network ropsten”。 I didn't see any error.我没有看到任何错误。

for future reference, do not post your api key that starts with 08ac7785... This means that anyone can use it, delete the api key if possible.以供将来参考,请勿发布以 08ac7785 开头的 api 密钥...这意味着任何人都可以使用它,如果可能,请删除 api 密钥。 It also seems that your Project namespace is not valid.您的Project命名空间似乎也无效。 A better new solution than to use HDWalletProvider, is to use the new truffle dashboard command to connect with metamask, which is connected to your hardware wallet比使用 HDWalletProvider 更好的新解决方案是使用新的 truffle truffle dashboard命令连接到连接到您的硬件钱包的 metamask

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM