cronos
cronos copied to clipboard
Only receiving mined (non pending) transactions when suscribing to "eth_newPendingTransactions"
So basically Im trying to run the following code using my node as my RPC to get the pending transactions.
package main
import (
"context"
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/rpc"
)
func main() {
rpcClient, err := rpc.Dial("ws://localhost:8546")
if err != nil {
panic(err)
}
ethClient, err := ethclient.Dial("ws://localhost:8546")
if err != nil {
panic(err)
}
rpcTxChan := make(chan common.Hash)
_, err = rpcClient.EthSubscribe(context.Background(), rpcTxChan, "newPendingTransactions")
if err != nil {
panic(err)
}
for {
h := <-rpcTxChan
_, pending, err := ethClient.TransactionByHash(context.Background(), h)
if err != nil {
panic(err)
}
fmt.Println(fmt.Sprintf("%s: %t", h.String(), pending))
}
}
The issue here is where I check if the transactions are pending or not, where in all cases they are not. Also, it seems that I only receive "new transactions" when lets say "a new block is added into my node" which suggest me that I am only seen the transactions that have been processed in the latest block, each time a new block gets mined.
I dont know if this is intended or Im missing something with my node configuration. At the moment I am only running a read only node (not a validator).
Thanks in advance!