Skip to content

Poll a range of block numbers from an evm node every x seconds

Notifications You must be signed in to change notification settings

alephao/evm-poller

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Eth Poller

Poll a range of block numbers from an evm node every x seconds

Example

package main

import (
	"context"
	"log"
	"time"

	"github.com/alephao/evm-poller/pkg/poller"
	"github.com/ethereum/go-ethereum/ethclient"
)

func main() {
	rpcUrl := "https://eth-mainnet.g.alchemy.com/v2/<key>"
	interval := 20 // polling interval in seconds

	log.Println("Connecting to ethereum...")
	client, err := ethclient.Dial(rpcUrl)
	if err != nil {
		log.Fatalf("failed to dial to RPC: %s", err.Error())
	}

	poller.Poll(context.Background(), client, time.Duration(interval), func(fromBlockNumber, toBlockNumber uint64) {
		log.Printf("Block Numbers: %d to %d", fromBlockNumber, toBlockNumber)
	})
}

About

Poll a range of block numbers from an evm node every x seconds

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages