Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/umbracle/eth-event-tracker
Ethereum event tracker
https://github.com/umbracle/eth-event-tracker
ethereum ethereum-etl events tracker
Last synced: about 1 month ago
JSON representation
Ethereum event tracker
- Host: GitHub
- URL: https://github.com/umbracle/eth-event-tracker
- Owner: umbracle
- License: mpl-2.0
- Created: 2021-11-02T07:51:28.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2021-11-28T15:57:06.000Z (about 3 years ago)
- Last Synced: 2024-06-20T05:22:18.465Z (6 months ago)
- Topics: ethereum, ethereum-etl, events, tracker
- Language: Go
- Homepage:
- Size: 102 KB
- Stars: 17
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Eth-event-tracker
Tracker of Ethereum events.
### Example
```
package mainimport (
"context"
"encoding/binary"
"flag"
"fmt"
"os"
"os/signal"
"syscall"web3 "github.com/umbracle/go-web3"
"github.com/umbracle/go-web3/abi"
"github.com/umbracle/go-web3/jsonrpc"
"github.com/umbracle/go-web3/tracker"boltdbStore "github.com/umbracle/go-web3/tracker/store/boltdb"
)var depositEvent = abi.MustNewEvent(`DepositEvent(
bytes pubkey,
bytes whitdrawalcred,
bytes amount,
bytes signature,
bytes index
)`)func main() {
var endpoint string
var target stringflag.StringVar(&endpoint, "endpoint", "", "")
flag.StringVar(&target, "target", "", "")flag.Parse()
provider, err := jsonrpc.NewClient(endpoint)
if err != nil {
fmt.Printf("[ERR]: %v", err)
os.Exit(1)
}store, err := boltdbStore.New("deposit.db")
if err != nil {
fmt.Printf("[ERR]: failted to start store %v", err)
os.Exit(1)
}tt, err := tracker.NewTracker(provider.Eth(),
tracker.WithBatchSize(20000),
tracker.WithStore(store),
tracker.WithEtherscan(os.Getenv("ETHERSCAN_APIKEY")),
tracker.WithFilter(&tracker.FilterConfig{
Async: true,
Address: []web3.Address{
web3.HexToAddress(target),
},
}),
)
if err != nil {
fmt.Printf("[ERR]: failed to create the tracker %v", err)
os.Exit(1)
}lastBlock, err := tt.GetLastBlock()
if err != nil {
fmt.Printf("[ERR]: failed to get last block %v", err)
os.Exit(1)
}
if lastBlock != nil {
fmt.Printf("Last block processed: %d\n", lastBlock.Number)
}ctx, cancelFn := context.WithCancel(context.Background())
go func() {
go func() {
if err := tt.Sync(ctx); err != nil {
fmt.Printf("[ERR]: %v", err)
}
}()go func() {
for {
select {
case evnt := <-tt.EventCh:
for _, log := range evnt.Added {
if depositEvent.Match(log) {
vals, err := depositEvent.ParseLog(log)
if err != nil {
panic(err)
}index := binary.LittleEndian.Uint64(vals["index"].([]byte))
amount := binary.LittleEndian.Uint64(vals["amount"].([]byte))fmt.Printf("Deposit: Block %d Index %d Amount %d\n", log.BlockNumber, index, amount)
}
}
case <-tt.DoneCh:
fmt.Println("historical sync done")
}
}
}()}()
handleSignals(cancelFn)
}func handleSignals(cancelFn context.CancelFunc) int {
signalCh := make(chan os.Signal, 4)
signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP)<-signalCh
gracefulCh := make(chan struct{})
go func() {
cancelFn()
close(gracefulCh)
}()select {
case <-signalCh:
return 1
case <-gracefulCh:
return 0
}
}
```You can query the ETH2.0 Deposit contract like so:
```
go run main.go --endpoint https://mainnet.infura.io/v3/... --target 0x00000000219ab540356cbb839cbe05303d7705fa
```