I've started up a local node (an avalanche node) and I've successfully connected to it using geth.

 ❯❯❯ geth attach
Welcome to the Geth JavaScript console!

instance: v0.8.4-rc.3
coinbase: 0x0100000000000000000000000000000000000000
at block: 0 (Wed Dec 31 1969 18:00:00 GMT-0600 (CST))
 modules: eth:1.0 net:1.0 rpc:1.0 web3:1.0

I'd like to subscribe to events on this node. The geth docs mention that this should be possible by sending json through the console. When I try to send this json, I get complaints about the json formatting:

> {"id": 1, "method": "eth_subscribe", "params": ["newHeads", {}]}
SyntaxError: SyntaxError: (anonymous): Line 1:6 Unexpected token : (and 2 more errors)

even though I copied this json directly from the docs (and it seems well formed to me).

The docs also mention that I need a minimum version of 1.4 and I have version 1.10:

 ❯❯❯ geth version
Version: 1.10.16-stable
Architecture: amd64
Go Version: go1.17.6
Operating System: darwin

How can I use geth to subscribe to events?

1 Answer 1


Figured out how to subscribe using a websocket client, wscat:

 ❮❮❮ wscat -c ws://
Connected (press CTRL+C to quit)
> {"id": 1, "method": "eth_subscribe", "params": ["newPendingTransactions"]}
< {"jsonrpc":"2.0","id":1,"result":"0x94be2b853229f8ea4b60b80b4a45b13e"}

I guess I was using the geth client incorrectly though it's not clear how geth should be used for subscriptions.

Your Answer

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

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