无法使用 Ganache GUI 连接到 Truffle 或 testrpc
Can not connect to Truffle or testrpc with Ganache GUI
我在 Windows 10 的官方网站上有来自 appx 的 Ganache GUI。当我在我的控制台 (WSL) 中 运行 Truffle 或 testrpc 网络并尝试在设置中从 Ganache GUI 连接到那里时,我在带有端口的文本框旁边收到错误消息:
The port is used by another application; please change it
端口来自 Truffle 或 testrpc。我怎样才能连接到那里?谢谢。
Ganache UI 运行 Ganache CLI 实例(即之前称为 TestRPC 的模拟以太坊实例)。如果您已经在端口 9545 上使用应用程序打开控制台 window,则 Ganache UI 无法在同一端口上启动新实例。
这些是对我有用的步骤:
- 开始甘那许-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
)
我将以下内容添加到我的 .zshrc 或 .bashrc 文件
# Get WSL Host IP
export WSL_HOST_IP="$(awk '/nameserver/ { print }' /etc/resolv.conf)"
这让我可以显示我的主机 IP,因此 WSL2 中的命令可以到达本地主机。
现在在 Ganache GUI 中创建一个工作区,并在服务器主机名设置下选择“0.0.0.0 - 所有接口”。
在您的 truffle 项目中,编辑 truffle-config.js 文件并将您的网络开发块设置为:
development: {
host: process.env.WSL_HOST_IP,
port: 7545,
network_id: "*" // Match any network id
}
现在当您 运行 truffle 迁移时,它应该连接到 Ganache GUI。
我在 Windows 10 的官方网站上有来自 appx 的 Ganache GUI。当我在我的控制台 (WSL) 中 运行 Truffle 或 testrpc 网络并尝试在设置中从 Ganache GUI 连接到那里时,我在带有端口的文本框旁边收到错误消息:
The port is used by another application; please change it
端口来自 Truffle 或 testrpc。我怎样才能连接到那里?谢谢。
Ganache UI 运行 Ganache CLI 实例(即之前称为 TestRPC 的模拟以太坊实例)。如果您已经在端口 9545 上使用应用程序打开控制台 window,则 Ganache UI 无法在同一端口上启动新实例。
这些是对我有用的步骤:
- 开始甘那许-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
)
我将以下内容添加到我的 .zshrc 或 .bashrc 文件
# Get WSL Host IP
export WSL_HOST_IP="$(awk '/nameserver/ { print }' /etc/resolv.conf)"
这让我可以显示我的主机 IP,因此 WSL2 中的命令可以到达本地主机。
现在在 Ganache GUI 中创建一个工作区,并在服务器主机名设置下选择“0.0.0.0 - 所有接口”。
在您的 truffle 项目中,编辑 truffle-config.js 文件并将您的网络开发块设置为:
development: {
host: process.env.WSL_HOST_IP,
port: 7545,
network_id: "*" // Match any network id
}
现在当您 运行 truffle 迁移时,它应该连接到 Ganache GUI。