Created
November 3, 2021 01:17
-
-
Save benhenryhunter/549bcb63870530576e6629427ca8c855 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
package main | |
import ( | |
"context" | |
"fmt" | |
"log" | |
ethereum "github.com/ethereum/go-ethereum" | |
"github.com/ethereum/go-ethereum/common" | |
"github.com/ethereum/go-ethereum/core/types" | |
"github.com/ethereum/go-ethereum/ethclient" | |
) | |
func main() { | |
client, err := ethclient.Dial("wss.url") | |
if err != nil { | |
log.Fatal(err) | |
} | |
contractAddress := common.HexToAddress("0x7AB2352b1D2e185560494D5e577F9D3c238b78C5") | |
query := ethereum.FilterQuery{ | |
Addresses: []common.Address{contractAddress}, | |
} | |
logs := make(chan types.Log) | |
sub, err := client.SubscribeFilterLogs(context.Background(), query, logs) | |
if err != nil { | |
log.Fatal(err) | |
} | |
for { | |
select { | |
case err := <-sub.Err(): | |
log.Fatal(err) | |
case vLog := <-logs: | |
fmt.Println(vLog) // pointer to event log | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment