Ethernet JSON-RPC Subscriber
This is a simple subscriber for the Ethernet JSON-RPC Ethereum protocol. It listens for changes on Ethernet chain and track transactions for requested addresses.
go install github.com/dkropachev/ethscan@latest
ethscan --endpoint https://mainnet.infura.io/v3/<API-KEY> --wallets 0xc940323bdacd868c319e9039ea5fddd35745e62d --start-block 19762452
ethscan --endpoint https://eth-mainnet.g.alchemy.com/v2/<API-KEY> --wallets 0xc940323bdacd868c319e9039ea5fddd35745e62d --start-block 19762452
ethscan --endpoint https://<NODE-NAME>.rpc.tatum.io/ --header "X-Api-Key: <API-KEY>" --wallets 0xc940323bdacd868c319e9039ea5fddd35745e62d --start-block 19762452
The library provides a subscriber that tracks transactions for requested addresses and stores them in memory
Usage of the library is simple.
You can create a new instance of the subscriber
pointing it to an Ethernet API endpoint:
sub, err := subscriber.NewMemSubscriber("https://mainnet.infura.io/v3/<API-KEY>")
if err != nil {
panic(err)
}
Subscribe to wanted addresses:
sub.Subscribe("0x1234567890abcdef1234567890abcdef12345678")
Start the subscriber
by calling the Start
method:
if err := sub.Start(); err != nil {
panic(err)
}
defer sub.Stop()
And read transactions:
for range time.NewTicker(time.Second * 5).C {
txs, err := sub.GetTransactions("0x1234567890")
if err != nil {
panic(err)
}
for _, tx := range txs {
txTxt, err := json.Marshal(tx)
if err != nil {
panic(err)
}
println(string(txTxt))
}
}
The library provides a subscriber that tracks transactions for requested addresses and sends them into a channel
Usage of the library is simple.
You can create a new instance of the subscriber
pointing it to an Ethernet API endpoint:
sub, err := subscriber.NewChanSubscriber(endpoint, opts...)
if err != nil {
panic(err)
}
Subscribe to wanted addresses:
sub.Subscribe("0x1234567890abcdef1234567890abcdef12345678")
Start the subscriber
by calling the Start
method:
if err := sub.Start(); err != nil {
panic(err)
}
defer sub.Stop()
And read transactions from the channel:
for tx := range sub.GetTransactionChan() {
if tx == nil {
break
}
txTxt, err := json.Marshal(tx)
if err != nil {
panic(err)
}
println(string(txTxt))
txTxt, err := json.Marshal(tx)
if err != nil {
panic(err)
}
println(string(txTxt))
}