Skip to content

vladmarchuk90/eth-block-api

Repository files navigation

Ethereum block info api

General

This is small http web-service that allows get total information on particular block on Ethereum blockchain network. Internally for getting information used Etherescan API.

External libraries used in this sevise

All actual external libraries used in application you can find in go.mod file. There are next:

  1. chi is used as router. It is a lightweight, idiomatic and composable router for building Go HTTP services.
  2. ttlcache library is used as in-memory cache.

API endpoint

One api endpoint is realized it's /api/block/{blockNumber}/total, where {blockNumber} is parameter and pointing to Ethereum network block you want getting information. Exploring blocks you are able on etherscan.

Response

Http api response is in json format and has the next structure {"transactions":NumberOfTransactionsInBlock,"amount":TotalAmountOfAllTransactions}. For example for block 14797288 you get the next response {"transactions":160,"amount":10.49336032072198}.

Installation and running

Clone the repository locally https://github.com/vladmarchuk90/eth-block-api.git after that you can run service by command go run cmd/web/*.go or previously build it by command go build cmd/web/*.go and after run ./main (if you built with default name). As well, you can build and run docker image by command docker-compose up -d (be sure you are in the project folder before running this comand).

Application settings

You can provide some settings (see config.json). File config json should be in project root folder if you use run command or together in one folder with executable if you previously built it. Default settings:

  1. "use_cache": true - turning on/off caching using, it's recommend to use cache.
  2. "api_key": "YourApiKeyToken" - you can get your personal api key at [https://etherscan.io/apis].
  3. "server_port": "80" - server port your service is running on.
  4. "api_template_url": "https://api.etherscan.io/api?module=proxy&action=eth_getBlockByNumber&tag=0xafa01b&boolean=true&apikey=YourApiKeyToken" - ethereum api template which used as template to compose block info request: tag is blockNumber in hex format and apikey is your personal api key.

About

Ethereum block api

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages