Ganache CLI

From UVOO Tech Wiki
Jump to navigation Jump to search

Installing & Using Ganache CLI on Ubuntu:Bionic or Debian:Buster Environment

This assumes you are suing nodejs v8.15.0 or greater or npm v6.4.1 or greater though may work on older.

Check dependencies

node -v
npm -v

Install dependencies

sudo apt update && apt install nodejs npm git

Install ganache-cli

sudo npm install -g ganache-cli

Run ganache-cli

ganache-cli

Run node console/repl

node

Run some commands in node console/repl

var Web3 = require('web3');
web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));

Using LXD

If you're having issues getting ganache-cli working on my localhost environment on Ubuntu, use a LXD container.

Installing LXD

Answer default to all questions.

sudo apt install lxd zfsutils-linux && lxd init

Open two terminals on your pc to interact with container and api

Change to ganache-test-container to whatever name you want.

Terminal 1

lxc launch ubuntu:bionic ganache-test-container
lxc exec ganache-test-container /bin/bash
apt update && apt install nodejs npm git
npm install -g ganache-cli
ganache-cli

Terminal 2

PORT=8545 PUBLIC_IP=localhost CONTAINER_IP=$(lxc list | grep ganache-test-container  | awk -F\| '{print $4}'| awk '{print $1}'); sudo iptables -t nat -I PREROUTING -i lo -p TCP -d $PUBLIC_IP --dport $PORT -j DNAT --to-destination $CONTAINER_IP:$PORT -m comment --comment "ganache-cli"

You should now be able to connect on you localhost via localhost:8545

Using Docker

References