Giter VIP home page Giter VIP logo

ethscan's Introduction

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.

Installation

go install github.com/dkropachev/ethscan@latest

Examples

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

Programmatic API

In-Memory Subscriber

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))
        }
    }

Chan Subscriber

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))
    }

ethscan's People

Watchers

Dmitry Kropachev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.