Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only receiving mined (non pending) transactions when suscribing to "eth_newPendingTransactions" #1446

Closed
1aBcD1234aBcD1 opened this issue May 20, 2024 · 1 comment

Comments

@1aBcD1234aBcD1
Copy link

1aBcD1234aBcD1 commented May 20, 2024

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants