Ropsten网络不确定

发布于 2025-01-27 19:18:58 字数 2759 浏览 3 评论 0原文

我正在尝试将MetAmask上的Ropsten TestNet连接到我的项目。但是我有一个我几天无法解决的问题。我对要重定向的页面上的定义如下。

当我希望它是一个错误时,我希望它给我一条消息。我现在正好遇到这个错误。 '确保您在Corrent网络上。将网络设置为Ropsten Test Network的

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]);

,这是我的Truffle-config.js文件。一切似乎正常。我不明白为什么它没有连接。你能帮我吗?

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"
      // }
    }
  },

 }
};

而且我还编写了终端此代码“松露迁移 - 网络ropsten”。我没有看到任何错误。

I'm trying to connect the Ropsten TestNet on Metamask to my project. 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'

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. 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". I didn't see any error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光暖心i 2025-02-03 19:18:58
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract SimplingsIdeas {
    
    struct Idea {
        string description; // Fikir açıklaması
        uint256 timestamp; // Kaydedildiği zaman
        address owner; // Fikri kaydeden kişinin adresi
    }
    
    mapping(uint256 => Idea) public ideas; // Fikirlerin kaydedileceği bir liste
    uint256 public ideaCount = 0; // Toplam fikir sayısını tutar

    // Yeni bir fikir kaydetmek için fonksiyon
    function addIdea(string memory _description) public {
        ideaCount++;
        ideas[ideaCount] = Idea(_description, block.timestamp, msg.sender);
    }

    // Belirli bir fikri getirmek için fonksiyon
    function getIdea(uint256 _id) public view returns (string memory, uint256, address) {
        require(_id > 0 && _id <= ideaCount, "Fikir bulunamadi.");
        Idea memory i = ideas[_id];
        return (i.description, i.timestamp, i.owner);
    }
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract SimplingsIdeas {
    
    struct Idea {
        string description; // Fikir açıklaması
        uint256 timestamp; // Kaydedildiği zaman
        address owner; // Fikri kaydeden kişinin adresi
    }
    
    mapping(uint256 => Idea) public ideas; // Fikirlerin kaydedileceği bir liste
    uint256 public ideaCount = 0; // Toplam fikir sayısını tutar

    // Yeni bir fikir kaydetmek için fonksiyon
    function addIdea(string memory _description) public {
        ideaCount++;
        ideas[ideaCount] = Idea(_description, block.timestamp, msg.sender);
    }

    // Belirli bir fikri getirmek için fonksiyon
    function getIdea(uint256 _id) public view returns (string memory, uint256, address) {
        require(_id > 0 && _id <= ideaCount, "Fikir bulunamadi.");
        Idea memory i = ideas[_id];
        return (i.description, i.timestamp, i.owner);
    }
}
嗳卜坏 2025-02-03 19:18:58

对于将来的参考,请勿发布以08AC7785开头的API密钥...这意味着任何人都可以使用它,请在可能的情况下删除API键。似乎您的项目名称空间无效。比使用HDWALLETPROVIDER更好的新解决方案是使用新的松露仪表板命令与MetAmask连接,该MetAmask连接到您的硬件钱包

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. It also seems that your Project namespace is not valid. 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文