[Ethereum] Subscription sample using websockets or IPC

eventsipcjson-rpcnodejs

So I was using the web3 API from the NodeJS 'web3' module very happily and it works very well (it uses HTTP transport AFAIU). But now I want to receive events from the server (without polling), and for that it seems I need to use the subscription API.

However, the documentation I just linked states subscriptions require a full duplex connection. Geth offers such connections in the form of websockets (enable with –ws) and ipc (enabled by default). Fair enough.

But, for the life of me, I cannot find any sample out there of how to connect via IPC/WebSockets. If the documentation included a simple hello world sample of a subscription, it would be rad.

Best Answer

you can also use netcat :

➜  ~  nc -U /home/XXX/.ethereum/geth.ipc
{"jsonrpc":"2.0","method":"eth_coinbase","params":[],"id":1}
{"jsonrpc":"2.0","id":1,"result":"0xeeeeeeeeeeeeeeeeeeeeededededede"}