0

Is it possible, to set up a new node using geth and subscripe to that node using web3js to save all transfers from the very beginning? Like could I scubribe to get "logs" events on a node that is currently syncing and newly setup using geth? I need all transfer events in a database and I have tried multiple ways to get this done which didnt work due to provider limitations and long taking pagination processes. This would be my last attempt doing it if possible.

1
  • you can't use a node until it syncs fully.
    – Nulik
    Jul 8, 2021 at 15:34

1 Answer 1

1

if there are lots of events, you need to query by block range, otherwise you will wait for hours without getting a response.

In golang this would look like:

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(event_signature)
topics = append(topics,signature)
filter.Topics= append(filter.Topics,topics)
filter.Addresses = nil 
logs,err := eclient.FilterLogs(context.Background(),filter)
if err!= nil {
    os.Exit(1)
}   

imports

"math/big"
"github.com/ethereum/go-ethereum/ethclient"
ethereum "github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"

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.