Created
July 8, 2020 09:24
-
-
Save MariusVanDerWijden/d560b48b23d7dc1565658fe1aaab6ae4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Watch for a Deposited event | |
watchOpts := &bind.WatchOpts{Context: ctx, Start: nil} | |
// Setup a channel for results | |
channel := make(chan *coolcontract.CoolContractDeposited) | |
// Start a goroutine which watches new events | |
go func() { | |
sub, err := ctr.WatchDeposited(watchOpts, channel) | |
defer sub.Unsubscribe() | |
}() | |
// Receive events from the channel | |
event := <-channel |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The call to ctr.WatchDeposited is non-blocking so as soon as it returns you will call sub.Unsubscribe which will prevent receipt of any events on the channel. I would suggest calling WatchDeposited without invoking a separate goroutine. Also, you should be listening on channel sub.Err() onto which come watcher errors.
Anyways, thanks for the article! It was really helpful to get some initial directions with all these Go bindings stuff.