git clone [email protected]:aburkut/eth-blocks.git
cd eth-blocks
nvm use 14.17
npm install
For reference look at .env-example file
ETHERSCAN_API_KEY=xx
- API_KEY value for Etherscan https://etherscan.io/ETHERSCAN_NETWORK=xxx
- network (homestead, ropsten, etc.) for EtherscanBLOCK_START=xxx
- the value indicates from which block number to start from for initial runBLOCKS_DDB_TABLE=blocks
- AWS Dynamodb table name where blocks will be storedTRANSACTIONS_DDB_TABLE=transactions
- AWS Dynamodb table name where transactions will be storedAWS_ACCESS_KEY_ID=xxx
- AWS access key idAWS_SECRET_ACCESS_KEY=xxx
- AWS secret access keyAWS_REGION=us-east-1
- AWS regionSTATE_BUCKET=eth-blocks-state
- AWS S3 bucketBLOCKS_STATE_FILE=blocks-state.txt
- AWS S3 state file to store state file with current processed block numberSMART_CONTRACT_NETWORK=ropsten
- network where smart contract will be deployedSMART_CONTRACT_ADDRESS=xxx
- smart contract addressPRIVATE_KEY=xxx
- private key to iteract with smart contract
npm run build
- compile TS files and install deps for dist foldernpm run start:dev:puller
- runs puller service (for local development)npm run start:dev:calc
- runs calc service (for local development)npm run deploy:contract
- deploy smart contract to specific networknpm test
- runs testsnpm run lint
- runs eslint checksnpm run lint:fix
- runs eslint checks and fixes problems
- Serverless architecture (cheap, scalable, no efforts to manage)
- Two AWS scheduled Lambda functions - puller and calc. The first one is responsible for pulling blocks and transactions from Etherscan API into database, runs on schedule every 1 minute. The second one calculates total number of blocks and ETH spent for gas gee for a day and puts the data into Solidity smart contract. Runs on schedule once a day at 00:10.
- S3 bucket to store the latest processed block number for puller lambda
- Database - AWS Dynamodb tables to store blocks and transactions
- contracts - contains Solidity smart contract
- src - contains source code of Node.js AWS Lambda functions and script to deploy smart contract
- terraform - contains terraform templates to provision AWS resources required by the application
- test - contains tests
export SMART_CONTRACT_NETWORK=xxx
- put network of your choiseexport PRIVATE_KEY=xxx
- put your private keynpm run deploy:contract
outputs smart contract address
To provision AWS resources need to run the following steps:
npm run build
to compile TS files and create dist folder that will be deployed as AWS lambda function by terraformcd terraform
export AWS_ACCESS_KEY_ID=xxx
&export AWS_SECRET_ACCESS_KEY=xxx
to give terraform access to AWS cloudterraform init
to download providers and modulesterraform plan
to see which AWS resources will be createdterraform apply
to provision infrastructure
The lambda functions a built on the top on Nest.js framework and Typescript.