Can not connect to Truffle or testrpc with Ganache GUI - blockchain

I have Ganache GUI from appx from official website on my Windows 10. When I run Truffle or testrpc network in my console (WSL) and try to connect there from Ganache GUI in settings, I get error message next to the textbox with a port:
The port is used by another application; please change it
the port is from Truffle or testrpc. How can I connect there? Thank you.

Ganache UI runs an instance of Ganache CLI (i.e. simulated Ethereum instance previously called TestRPC). If you already have a console window open with an application on port 9545 then Ganache UI cannot start a new instance on that same port.

I add the following to my .zshrc or .bashrc file
# Get WSL Host IP
export WSL_HOST_IP="$(awk '/nameserver/ { print $2 }' /etc/resolv.conf)"
This allows me to surface my host ip, so commands in WSL2 can reach the localhost.
Now create a workspace in Ganache GUI and under the server HOSTNAME settings choose "0.0.0.0 - All Interfaces".
In your truffle project edit the truffle-config.js file and set your network development block to this:
development: {
host: process.env.WSL_HOST_IP,
port: 7545,
network_id: "*" // Match any network id
}
Now when you run truffle migrate, it should connect to the Ganache GUI.

These are the steps that worked for me:
Start ganache-ui
Configure truffle's network in truffle-config.js:
networks: {
development: {
host: "127.0.0.1", // Localhost (default: none)
port: 7545, // Standard Ethereum port (default: none)
network_id: "*", // Any network (default: none)
},
...
Run truffle console (NOT truffle develop)

Related

How to connect to Mosquitto MQTT Broker, that is running on a Google Cloud Virtual Machine Instance, using mqtt.js

What I am trying to achieve: I have a Mosquitto MQTT Broker running on a Google Cloud virtual machine (Ubuntu), and I want to be able to connect to it from my local PC using mqtt.js
My setup
I have created a VM instance in Google Cloud, running Ubuntu 20.04.LTS.
Some of the settings:
Firewall – allow HTTPS and allow HTTP
Firewall rule – opens port 1883
I installed Mosquitto MQTT Broker (version 1.6.9) on this VM.
I was able to verify the installation and that it was running, by opening to SSH terminals, one to publish, one to subscribe
mosquitto_sub -t test
mosquitto_pub -t test -m “hello”
Then I read that when I want to connect to VMs using third-party tools, I must create and upload my own SSH keys to VMs:
ssh-keygen -t rsa -f C:\keys\VM_KEYFILE -b 2048 pwd: ****
I got two files now, the private and public keys:
VM_KEYFILE
VM_KEYFILE.pub
I then used icacls to modify the private key’s permissions:
icacls.exe VM_KEYFILE /reset
icacls.exe VM_KEYFILE /grant:r “$($env:username):(r)”
icacls.exe VM_KEYFILE /inheritance:r
I then successfully connected ot the VM from a Windows console:
ssh -i "VM_KEYFILE" username#vm_public_ip_address
So now I want to try and connect using node.js
I already have a javascript file that uses mqtt.js to connect to some of the public MQTT brokers, e.g. HiveMQ
Some of its settings are:
let broker_host = 'broker.hivemq.com';
let broker_port = 1883;
let client_id = 'my_client_1';
const connection_options = {
port: broker_port,
host: broker_host,
clientId: client_id,
clean: true,
keepalive: false
};
My question: How would I modify this JavaScript file to connect to the MQTT broker that is running in the Google Cloud VM
There is no username/password/authentication set up for the broker itself, just the VM.
I tried something like this, but I have no idea how to use the SSH key
let broker_host_gcm_vm = 'https://<vm_public_ip_address>
UPDATE
I can connect to the broker from both (a) MQTT Explorer, and (b) MQTTX deskptop app.
All I have to enter for the connection details is:
Host: mqtt://<ip address>
Port: 1883
Then I can publish / subscribe successfully.
I tried changing my JavaScript connection to the following, but I still can't connect from here:
let broker_host_gcm_vm1 = 'mqtt://<ip address>';
I found the problem.
Let's say the host IP address is 11.22.33.44
The host was none of these:
let broker_host = 'http://11.22.33.44';
let broker_host = 'https://11.22.33.44';
let broker_host = 'mqqt://11.22.33.44';
let broker_host = 'mqtts://11.22.33.44';
But was simply this:
let broker_host = '11.22.33.44';
Simple when you know how :)

Ganache Issue-Not showing the available networks

Iam trying to connect Ganache in mac, when i started Ganache ,its not showing the available accounts and open the server screen - unable to select the host name. It has only one option "hostname of the server 0.0.0.0 - All Interfaces."
I've tried
Restarting Ganache,
Restarting Computer,
Uninstalling from Applications and Reinstalling,
Ganache Downloaded Ganache from
https://trufflesuite.com/ganache/
FYI:i have installed truffle suite
Truffle v5.5.20 (core: 5.5.20)
Ganache v7.2.0
Solidity v0.5.16 (solc-js)
Node v16.15.1
Web3.js v1.7.4
Anyone has idea how resolve this issue.
Thanks in Advance
Laxmi
your truffle.config.js should have this minimum configuration to connect
module.exports = {
contracts_build_directory: "./public/contracts",
networks: {
development: {
// in hte truffle HOSTNAME down set the correct host. "0.0.0.0" should accept this
host: "127.0.0.1",
port: 7545,
network_id: "*",
},
},
compilers: {
solc: {
version: "0.8.13",
},
},
If ganache is running, when you start your truffle project it should automatically connect

How to change default ganache-cli ip address in brownie ide?

When I run brownie console the ganache-cli starts by default at 127.0.0.1 address. How to change this address to 0.0.0.0?
I've tried to modified config located at ~/.brownie/network-config.yaml. I've changed host and port in the following section
development:
- name: Ganache-CLI
id: development
cmd: ganache-cli
host: http://0.0.0.0
cmd_settings:
port: 8549
gas_limit: 12000000
accounts: 10
evm_version: istanbul
mnemonic: brownie
but after restart only port was updated correcly.
There are two ways to do this:
Edit the network
Add a new network with the URL you're looking for
Edit the network
brownie networks modity development host=http://0.0.0.0
Add a new network
brownie networks add development ganache-zero cmd=ganache-cli host=http://0.0.0.0 accounts=10 mnemonic=brownie port=8545
Or
brownie networks add Ethereum ganache-zero host=http://0.0.0.0:8545 chainid=1337

Truffle migrate is not deploying to Ganache

I tried command truffle migrate --reset, but it is unable to connect to Ganche
here is the error:
This is the code inside truufle-config.js file:
And these are the RPC server details:
It seems there is a typo in your truffle-config.js: post instead of port.
Try this out:
networks: {
development: {
host: "127.0.0.1",
port: 9545,
network_id: "*"
}
},
Then:
Double check the settings on Ganache match with the ones on truffle-config.js
Check that Ganache is running.
And finally open a new terminal and run the following 2 commands in the same folder where the file truffle-config.js is hosted:
truffle console ––network development
migrate ––reset
Try this out:
networks: {
development: {
host: "127.0.0.1",
port: 7545,
network_id: "*",
}
},
Open the terminal and run the following command in the same folder where the file truffle-config.js is hosted:
truffle console ––network development

Truffle configuration

truffle migrate --compile-all --reset --network ganache
Compiling your contracts...
Everything is up to date, there is nothing to compile.
Unknown network "ganache". See your Truffle configuration file for available networks.
By default you don't need to specify the --network, truffle will automatically connect to Ganache. On the other hand, if you want to have the name ganache configured as a network, you will have to modify your truffle-config.js file as follows:
networks: {
//...,
ganache: {
host: "127.0.0.1",
port: YOUR_GANACHE_PORT, // (default: 5777)
network_id: "YOUR_GANACHE_NETWORK_ID", // (default: *)
},
//...
}
Check this picture to see Ganache port and network_id