【问题标题】:Can not connect to Truffle or testrpc with Ganache GUI无法使用 Ganache GUI 连接到 Truffle 或 testrpc
【发布时间】:2019-05-24 18:49:54
【问题描述】:

我在 Windows 10 上从官方网站的 appx 获得 Ganache GUI。当我在控制台 (WSL) 中运行 Truffle 或 testrpc 网络并尝试从设置中的 Ganache GUI 连接时,我在文本框旁边收到错误消息一个端口:

该端口被另一个应用程序使用;请改一下

端口来自 Truffle 或 testrpc。我怎样才能在那里连接?谢谢。

【问题讨论】:

    标签: blockchain ethereum truffle appx ganache


    【解决方案1】:

    Ganache UI 运行一个 Ganache CLI 实例(即以前称为 TestRPC 的模拟以太坊实例)。如果您已经在端口 9545 上打开了一个带有应用程序的控制台窗口,则 Ganache UI 无法在同一端口上启动新实例。

    【讨论】:

    • 那么如何将 GanacheUI 连接到 Truffle?
    • 情况正好相反。您希望将 Truffle 连接到 GancheUI。在您的truffle.js 配置文件中,确保host127.0.0.1port9545network_id5777*。这将允许您随后能够使用 Truffle 在您通过 GancheUI 创建的模拟网络上部署合约并与之交互。
    【解决方案2】:

    这些是对我有用的步骤:

    • 启动 ganache-ui
    • truffle-config.js中配置truffle的网络:
      networks: {
        development: {
          host: "127.0.0.1",     // Localhost (default: none)
          port: 7545,            // Standard Ethereum port (default: none)
          network_id: "*",       // Any network (default: none)
        },
        ...
    
    
    • 运行truffle console(不是truffle develop

    【讨论】:

      【解决方案3】:

      我将以下内容添加到我的 .zshrc 或 .bashrc 文件中

      # Get WSL Host IP
      export WSL_HOST_IP="$(awk '/nameserver/ { print $2 }' /etc/resolv.conf)"
      

      这允许我显示我的主机 ip,因此 WSL2 中的命令可以到达本地主机。

      现在在 Ganache GUI 中创建一个工作区,并在服务器 HOSTNAME 设置下选择“0.0.0.0 - 所有接口”。

      在您的 truffle 项目中编辑 truffle-config.js 文件并将您的网络开发块设置为:

      development: {
        host: process.env.WSL_HOST_IP,
        port: 7545,
        network_id: "*" // Match any network id
      }
      

      现在,当您运行 truffle migrate 时,它​​应该连接到 Ganache GUI。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-12-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-03-12
        • 2019-05-21
        • 2022-08-22
        • 1970-01-01
        相关资源
        最近更新 更多