3

My goal: To simulate the Ethereum blockchain with different clients. So, they create their own accounts, i.e. public/private keys, and store them locally. So all are for testing.


Assume, I have set up a private chain on computer A. Can I install MetaMask on computer B, and connect to computer A's private chain?

If YES, how can I do that?

If NO, how can I connect two nodes (each on a different machine and having the regular IP address, not a static one) so they can connect to the private chain with a minimal setup?

2 Answers 2

3

You can do it with using both ways, having the two computers networked together.

Using Metamask;

select network as Custom RPC put the custom url as http://[ComputerA's ip address]:[rpc port]

eg:

If computer A's ip address is 192.168.8.100 and rpc port is 8545 then use,

http://192.168.8.100:8545

enter image description here enter image description here

Using web3;

As one of your own questions How can I connect my HTML user interface to my Ethereum private chain? you can use

web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));

with the slight change of; instead localhost replace the ip address of the other computer (in your case computer A's ip address in the LAN) and the 8545 with port number.

eg:

If computer A's ip address is 192.168.8.101 and rpc port is 8545 then use,

web3 = new Web3(new Web3.providers.HttpProvider("http://192.168.8.101:8545"));

EDIT: It's needed to have RPC enabled in the computer A allowing the computer B to access it with

--rpc --rpcport "8545" --rpccorsdomain "[commputer B's ip address OR *]" --rpcaddr "[computer A's ip address]" 
0
1

This answer is just a complementary to the answer provided by @Achala Dissanayake, and I'd like to thank him, again!

To make two computers on different Internet networks (e.g. Wifi, under a firewall or any combination of setting) connect to a machine A and send transactions/smart contracts to the private chain, in machine A, we can do the following:

First, we install Hamachi in all machines including machine A. Hamachi allows the computers to have an IP address and put them in a virtual LAN. Then each machine adds the IP address of machine A in Hamachi software (it's very easy to do that).

Assume machine A's IP address provided by Hamachi is: x.y.z.w

To initiate a private chain in machine A, we run the folllowing command line :

geth --identity "MyNodeName" --rpc --rpcport "8545" --rpccorsdomain "*" 
--datadir Users/TestChain --port "30303" --rpcaddr 
"x.y.z.w"  --nodiscover --rpcapi "db,eth,net,web3,personal" --
networkid 123 init /Users/CustomGenesis.json

The second line will be:

geth --identity "MyNodeName" --rpc --rpcport "8545" --rpccorsdomain "*" 
--datadir Users/TestChain --port "30303" --nodiscover --rpcaddr 
"x.y.z.w"    --rpcapi "db,eth,net,web3,personal" --networkid 123 
console

Please pay attention to

--rpcaddr "x.y.z.w"

Please note that machine A can independently install Hamachi, get it IP and run the above lines without knowing anything about other machines.

In practice, the "x.y.z.w" will be an IP address provided by Hamachi.

Finally, in each machine willing to connect to machine A, via Metamask, we set up a "Custome RPC" and set the following as new RPC URL:

http://x.y.z.w:8545

Note, "Custome RPC" is an option in Metamask that allows us to provide our network details.

That's it. Now they can interact with machine A with a minimal setting, and the other nodes don't even need to install or run "geth", etc.


I've tested the above idea: I ran a private chain on a Macbook pro and connected to it using a Windows Vista laptop. They were connected to two different Wifi networks.

1
  • Great :), the necessity is to have a proper network connection between the two computers and computers being able to talk using the ip addresses (you will get this in a home wifi inside the NAT with private ips) and you have achieved it with hamachi. Good luck with your works :) Commented Oct 13, 2017 at 11:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.