In this Project we are going to get log of ethereum network in real time using websocket with Alchemy, We will try to get event from the logs of any specifiy Smart Contract which is deployed on-Chain and index it data.
https://docs.alchemy.com/reference/eth-subscribe
- We will connect to Ethereum with help Alchemy RPC (used filter to get only those transation which are belong to contract which we want to track)
- Connect to DB who have different Table
2.1 Blockchain Event info (ChainName,ChainID,blockNumber,Total Amount Transfer)
blockNumber it will help us to know where to start get logs and where we left when service close
2.2 Tables With Event Name , their fields which we store and Do index on data - Once we connect and get logs it time to get event signature and convert the values (data and topics).
- Time to Store Them into DB and Index the data.
- Then we will Expose two Endpoint 5.1 get Contract Blanace (Sum by Total Amount Transfer from start of service). 5.1 tell that transaction hash belong to that contract or not
- Nodejs (express Server)
- Postgress Database (with Docker)
- Copy ABI in Config folder.
- Run postgressDB with Docker
cd pg-compose
docker-compose up -d
- Run
node init.js
inside utils folder it will covert ABI into to ABI siginature in config folderevent_signature.json
and create table for every Event and it Indexing - Run
node index.js
it will start node server and you can connect it with REST API's
## getTotalAmount
curl --location --request GET 'http://localhost:8080/api/getTotalAmount'
## verifyHashDB This will check from Database which we store with program blockchain that transaction hash exist
curl --location --request GET 'http://localhost:8080/api/verifyHashDB?transactionHash=0x320b95cef4c3cfe7ffca91f8bd9e5734cdba99cafc430004a50b9f553194929b'
## verifyHash This will check from real blockchain that transaction hash exist
curl --location --request GET 'http://localhost:8080/api/verifyHash?transactionHash=0x320b95cef4c3cfe7ffca91f8bd9e5734cdba99cafc430004a50b9f553194929b'
config
it carry all the configration of the project like ABI , it signature which is used to create tables and indexing on DB and all ENV valuesconstants
it will carry all the dynamic schema of data based whihc we used to do all the operation on DB like Create table , Insert data, Get data , Indexing and Function (which help as dynamic)controller
it have API endpoint logicevent
it have logic related to Convert ABI to it signature ,Get event logs from blockchain Decode the logs values and store them into DBmodule
it have logic related to DB connection and Query Execution.utils
it have logic related setup everything like create ABI signature and used that ABI signature to create table, index and function.pg-compose
this where we have compose file of DB with docker