如何从Vagrant box运行ganache-cli?

时间:2018-09-17 08:50:50

标签: vagrant ethereum metamask

我正在Vagrant框中运行ganache-cli,并尝试将Metamask(Google Chrome)连接到它。但是Metamask无法连接到它。如果ganache-cli在主机上运行,​​它将连接。这是我的流浪文件

流浪文件

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(2) do |config|
  config.vm.hostname = 'ethereum'
  config.vm.box = "ubuntu/bionic64"
  config.vm.provision :shell, path: "setup_dev_env.sh"
  config.vm.box_check_update = false

  config.vm.network "forwarded_port", guest: 3000, host: 3000, host_ip: "127.0.0.1"
  config.vm.network "forwarded_port", guest: 8545, host: 8545, host_ip: "127.0.0.1"

  config.vm.synced_folder "SOME_PATH", "/home/vagrant/code"
  config.vm.provider "virtualbox" do |vb|
    vb.gui = false
    vb.memory = "4096"
  end
end

setup_dev_env.sh的内容

sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install -y --allow-unauthenticated python3-pip mypy build-essential ethereum npm

sudo npm install -g ganache-cli
sudo apt-get update

1 个答案:

答案 0 :(得分:2)

ganache-cli --host 0.0.0.0开始ganache-cli,然后在Metamask中以Custom RPC的形式在New RPC URL中输入http://0.0.0.0:8545的详细信息