Skip to content

This is a simple go module for polling the flow blockchain for events.

Notifications You must be signed in to change notification settings

peterargue/flow-event-poller

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

flow-event-poller

This is a simple go module for polling the Flow blockchain for events. You provide a list of events and a polling interval, and receive a channel on which you can receive your subscribed events.

If you have a very simple use case, check out the simple example for how to poll for events directly using the flow-go-sdk.

Usage

ctx := context.Background()

client, err := client.New("access.mainnet.nodes.onflow.org:9000", grpc.WithInsecure())
if err != nil {
	log.Fatalf("error creating client pool: %v", err)
}

sub := poller.NewEventPoller(client, 60*time.Second)
ch := sub.Subscribe([]string{
	"A.1654653399040a61.FlowToken.TokensWithdrawn",
})

go func() {
	for {
		select {
		case <-ctx.Done():
			return
		case e := <-ch:
			eventHandler(e.Event)
		}
	}
}()

if err := sub.Run(ctx); err != nil {
	log.Fatalf("error running event follower: %v", err)
}

Then you implement eventHandler to suit your needs.

Running Example

There is a runnable example implementation in cmd/example/main.go which demonstrates how to use this module.

go run cmd/example/*.go

About

This is a simple go module for polling the flow blockchain for events.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages