I'm trying to write a program in Go to watch pending transactions, using a geth full node that I'm connected to over websockets. I'm pretty sure I have to use the github.com/ethereum/go-ethereum/eth/filters package to create a new event system, on which I can then call SubscribePendingTxs, but I don't know what I should use as the backend.

  • geth node goes as backend. RPC service should be enabled
    – Nulik
    Feb 8 at 22:43

This is how you do it if you want to make two type of calls at the same time, via Ethereum client and raw RPC (web):

; ETH_NODE_RPC_URL="http://localhost:8545"
const RPC_URL = os.Getenv("ETH_NODE_RPC_URL")
rpcclient, err=rpc.DialContext(context.Background(), RPC_URL)
eclient = ethclient.NewClient(rpcclient)

filter := ethereum.FilterQuery{}
filter.FromBlock = big.NewInt(block_num_from)
filter.ToBlock = big.NewInt(block_num_to)
topics := make([]common.Hash,0,1)
signature := common.BytesToHash(evt_name_registered2)
topics = append(topics,signature)
filter.Topics= append(filter.Topics,topics)
filter.Addresses = nil 
logs,err := eclient.FilterLogs(context.Background(),filter)
if err!= nil {
for _,log := range logs {

This code snippet I am using it to scan events, but for pending logs it should be similar. Try to make it work over HTTP first, then switching the medium to web service should be trivial.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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