Edgar's blog

13 Aug 2021

adding a new event to geth

Adding new event

Let’s add a new event to geth/bsc’s websocket based eth_subscription.

first check bsc/eth/filters/api.go, lets copy the method, NewPendingTransactions and call it something else, like NewIncomingTime

but our body of the Submit callback will instead be:

	gopool.Submit(func() {
		t := time.NewTicker(time.Second * 2)
		defer t.Stop()

		for {
			select {
			case tk := <-t.C:
				notifier.Notify(rpcSub.ID, tk)
			case <-rpcSub.Err():
			case <-notifier.Closed():

compile with make in root of the geth code base, the binary is at build/bin/geth

testing it

use wscat (npm i -g wscat) and connect to your node, on the default its

$ wscat -c ws://localhost:8546

and enter:

> {"id": 1, "method": "eth_subscribe", "params": ["newIncomingTime"]}

Now every two seconds you’ll have an incoming subscription