Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to curl to Ethereum geth node on local network (not localhost)

Tags:

curl

geth

I have geth running on local network (separate machine). curl'ing to http://localhost:8545 works just fine. How do I curl to that geth node from another machine on my private network? Curling to http://10.x.x.x:8545 just returns connection refused.

geth itself is all up and running on the other 10.x.x.x machine just fine and geth attach, curl, etc all work on localhost on that box.

e.g. this works:

curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":67}' http://localhost:8545

result: ➜  {"jsonrpc":"2.0","id":67,"result":"Geth/v1.9.17-unstable-5b081ab2-20200714/darwin-amd64/go1.13.6"}


this fails (from another machine on that private network):

curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":67}' http://10.x.x.x:8545

result ➜ curl: (7) Failed to connect to 10.x.x.x port 8545: Connection refused

(using real IP's instead of x's of course)

Both nodes communicate just fine otherwise (ssh, browse websites, file sharing, etc...)

like image 902
Adivate Avatar asked Nov 02 '25 06:11

Adivate


1 Answers

You'll need to enable --rpcaddr flag to accept connection. from somewhere/anywhere, --wsaddr flag for websocket connections.

Example:

$ geth --rpc --rpcaddr 0.0.0.0
$ geth --rpc --wsaddr 0.0.0.0
$ geth --rpc --rpcaddr 0.0.0.0 --wsaddr 0.0.0.0

This allows you to geth to accept connections from any interface and network. You can geth attach, curl, web3 provider.

like image 163
Ming Avatar answered Nov 04 '25 19:11

Ming



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!