Avalanche C-Chain indexer proof of concept
- Clone this repo
- Execute
docker-compose up
in the repository root, docker will pull the required images and exeute the services.
Running docker-compose up
the following services will start:
- api this is the REST backend server exposing on port 3000 the endpoints listed below in order to read data from the db
- indexer this is the indexer engine, listening for avalanche chain changes and running an ETL in order to store ready-to-read transactions on the db
- mongo the monogodb database
- mongo-express exposing on port 5000 the frontend to interact with the database
Exposed by the API there's the following endpoints:
GET /topWallet
: retrieve top 100 wallets by balanceGET /txsByValue
: retrieve transactions list order by $AVAX value moved, limited to 100 entriesGET /walletTxCount?w=<wallet>
: retrieve number of txs sent or receivedGET /walletTxs?w=<wallet>
: retrieve transaction list order byblockNumber
andtransactionIndex
In the repo root there's the postman collection json ava-idx.postman_collection.json
with the endpoint already configured
Currently in the ETL the wallets balance is refetched from the chain every time for all the wallets found on new transactions, this can guarantee that is always fresh but can be expensive in terms of rpc provider. A better solution could be to fetch the balance from the chain the first time and just altering that with the balance moved with the tx:
tx.to
wallet balance increased by thetx.value
tx.from
wallet balance decreased by thetx.value
and the gas used by the tx
Currently we're using a temp table on db for raw transactions, the ETL periodically load the txs and once transformed saves them in the final collection. This is sub optimal and can be improved with a different architecture, for example a messase queue on SQS with all the raw transactions and a serverless process for the ETL consuming it.
Documentation can be improved and a swagger open api can be published in order to make dev life easier.
mongodb
: db clientpino
: lightweight logger (winston alternative)express
: http server frameworkviem
: ethers.js alternative to access the chain rpc providertoad
-scheduler: simple task schedulerlodash
: utilities