Skip to content

daniel-burghardt/ethereum-watcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ethereum Watcher

Ethereum Watcher is a service built in Go to track transactions from subscribed addresses on the Ethereum network.

It provides an API for easy subscribing and transactions fetching.

Additionally, a webhook URL can be configured to receive live notifications about new transactions pertaining to the subscribed addresses.

API

Configuration

The following environment variables can be configured:

  • ETH_SERVER_URL (optional): specifies which RPC node to connect to. Defaults to https://cloudflare-eth.com;
  • WEBHOOK_URL (optional): when provided the service will make a post request to this URL informing about new transactions for one or more subscribed addresses;

Endpoints

GET /current-block

Returns the latest block the service has ingested.

POST /subscribe/{address}

Subscribes {address} to the watcher service. Once subscribed, its transactions will be tracked and persisted in the service's storage.

GET /transactions/{address}

Returns an array of all transactions sent to or received by {address} after the time of subscription.

Note: The API server is started by default on port 3000. The base URL for API calls is http://localhost:3000 when running locally.

Running

Requirements

  • Go 1.22 (or higher) installed (this is essential for the API to function properly);

Command Line

The service can be started with go run . on the root folder.

If you want to connect to an alternative RCP node (such as a testnet one) the environment variable can be set with export ETH_SERVER_URL=https://rpc.sepolia.org before running go run ..

In the same fashion, the webhook URL can be set with export WEBHOOK_URL=https://myserver/webhook.

Considerations

Performance

The current implementation uses the eth_blockNumber method to fetch the latest block from the ledger. However, this method presented some lag in the tests conducted, taking a few seconds after the closing time of the latest block to return the updated value.

An alternative version calling eth_getBlockByNumber directly until the response is not empty is implemented on separate a branch performance-improvement. This approach presented a significant performance improvement (delays below 1s) over the current one, but it relies on RPC calls to error, which resulted in a different responses in the tests conducted (with https://rpc.sepolia.org and https://cloudflare-eth.com) depending on the RPC node. Although promising this approach requires further experimentation.

A third alternative was tested using eth_newBlockFilter and eth_getFilterChanges to get the latest block information. Although it presented great performance improvement (similar to the one described above), Cloudflare's Public RPC node doesn't support either of the methods as of now: see docs.

Webhook

The webhook calls don't currently implement any retry logic, which should be done in future work.

An even more reliable approach would be to implement an event-based system such as Kafka as to guarantee delivery and minimize latency.

About

Ethereum Watcher is a service built in Go to track transactions from subscribed addresses on the Ethereum network.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages