Daily statistics for Ethereum blockchain
- Install node.js or run
nvm usefrom the repo. - Install git lfs
- Install yarn
npm install -g yarn
$ cp .env.default .env- Open .env in a text editor and set the following variables:
- ETHEREUM_NODE_URL (Use websockets as protocol)
Example of .env file:
ETHEREUM_NODE_URL=wss://rinkeby.infura.io/ws/v3/.....
NODE_ENV=dev
DB_HOST=localhost
DB_NAME=ethereum_stats
DB_USER=ethereum-stats
DB_PASS=ethereum-stats
DB_PORT=5435
- Setup account
$ yarn setup:account- Add gas through facet
- this depends on what network you plan on testing
- Deploy contract
$ yarn setup:contractStart the service
$ docker-compose up -d db # spin up local postgresql 14
$ yarn install
$ yarn start$ npm install --global yarn-
Service to connect to ethereum blockchain
-
Postgresql database
- run from terminal
docker-compose up -d dbto setup local postgresql
- run from terminal
$ yarn install
$ yarn start-
Currently the contract is just appending Stats to a variable. How much "Stats" is possible to save on ethereum blockchain? What's the price?
-
Gas optimizations, which I'm sure there is plenty
- Error handling in general (always a problem with typescript), one case stands out and that is http connection timeout (or web socket timeouts in this case)
- Stale/dead web socket connection to ethereum node (didn't see this one happen but I'm sure it can)
- Update number of unit tests, especially for src/sync.ts
- Local node to test run integrations test on the blockchain
- E2E test which connects the database and the ethereum blockchain
- Currently if the process fails and restarts after X amount of days, the non synced stats will not be written to the ethereum blockchain. I would add another database entity Stats which would stand for all the daily stats already written to the blockchain.
Define what small level tasks I want to accomplish
- Setup postgres as docker service
- Setup typeorm and connect to postgres
- Setup testing
- Setup integration testing
- check if date is in format in smart contract "YYYY-mm-dd"
- Setup Block model
- Create a query to extract and sum all gas fees for that day.
- Write to Smart Contract to save Gas Spend on a given day
- Catch errors while reading/writing from ethereum blockchain
- Add retry logic to ethereum.service.fetchBlock()...
- Setup github actions to automatically run tests
- Setup hardhat for contract development (I assume this is a must)
- Write synced timestamps to database to reduce calls gas when trying to resync
- Check if websocket connection to ethereum node gets stale
- Setup local etherum network (geth | ganache cli)
- Move contract to mappings instead of an array
- Setup project, basic typescript. ✓
- MVP for reading form Ethereum blockchain ✓
- Try connecting to the blockchain and read blocks/transactions ✓
- Based on data structures and relation ships define which database will be used ✓
- Setup a ethereum service as an abstraction for reading. ✓
- MVP for Smart Contract ✓
- Develop & publish smart contract ✓
- Connect service to Smart Contract ✓
- Look for edge cases when reading from Ethereum blockchain