From 7f366e5899531a6de0d70f32827296cc81e197c4 Mon Sep 17 00:00:00 2001 From: Konstantina Blazhukova Date: Mon, 13 Jan 2025 16:52:43 +0200 Subject: [PATCH] Creates new package for rest api explorer endpoints Signed-off-by: Konstantina Blazhukova --- packages/http-explorer-server/README.md | 84 +++++++++++++++++++++ packages/http-explorer-server/package.json | 35 +++++++++ packages/http-explorer-server/tsconfig.json | 23 ++++++ 3 files changed, 142 insertions(+) create mode 100644 packages/http-explorer-server/README.md create mode 100644 packages/http-explorer-server/package.json create mode 100644 packages/http-explorer-server/tsconfig.json diff --git a/packages/http-explorer-server/README.md b/packages/http-explorer-server/README.md new file mode 100644 index 0000000000..7bfce90e02 --- /dev/null +++ b/packages/http-explorer-server/README.md @@ -0,0 +1,84 @@ +# Hedera HTTP Explorer Server + +This package provides REST API endpoints for exposing EVM-centric data from the Hedera network, similar to Etherscan's API. It supports querying token transfers for ERC20, ERC721, and ERC1155 tokens, as well as fetching tokens owned by an address. + +## Features + +- ERC20 token transfer events +- ERC721 NFT transfer events +- ERC1155 multi-token transfer events +- Tokens owned by an address +- Pagination support +- Block range filtering +- Address filtering +- Contract filtering + +## API Endpoints + +### Token Transfers + +Get ERC20 token transfers: +``` +GET /api?module=account&action=tokentx&address={address}&contractaddress={contractaddress}&startblock={startblock}&endblock={endblock}&page={page}&offset={offset}&sort={asc|desc} +``` + +Get ERC721 (NFT) token transfers: +``` +GET /api?module=account&action=tokennfttx&address={address}&contractaddress={contractaddress}&startblock={startblock}&endblock={endblock}&page={page}&offset={offset}&sort={asc|desc} +``` + +Get ERC1155 token transfers: +``` +GET /api?module=account&action=token1155tx&address={address}&contractaddress={contractaddress}&startblock={startblock}&endblock={endblock}&page={page}&offset={offset}&sort={asc|desc} +``` + +### Account Tokens + +Get tokens owned by an address: +``` +GET /api/account/{address}/tokens?page={page}&offset={offset} +``` + +## Installation + +```bash +npm install +npm run build +``` + +## Usage + +```bash +npm start +``` + +## Configuration + +The server can be configured through environment variables: + +- `PORT` - Server port (default: 3000) +- `HOST` - Server host (default: localhost) +- `RATE_LIMIT` - Rate limiting configuration +- `PAGINATION_DEFAULT_SIZE` - Default page size (default: 100) +- `PAGINATION_MAX_SIZE` - Maximum page size (default: 1000) +- `MAX_BLOCK_RANGE` - Maximum block range for queries (default: 1000) +- `REDIS_URL` - Redis connection URL for caching + +## Development + +```bash +# Install dependencies +npm install + +# Build +npm run build + +# Run tests +npm test + +# Lint +npm run lint + +# Fix linting issues +npm run lint:fix +``` diff --git a/packages/http-explorer-server/package.json b/packages/http-explorer-server/package.json new file mode 100644 index 0000000000..738c0d95cd --- /dev/null +++ b/packages/http-explorer-server/package.json @@ -0,0 +1,35 @@ +{ + "name": "@hashgraph/http-explorer-server", + "version": "0.1.0", + "description": "HTTP server exposing Etherscan-like REST APIs for Hedera network", + "main": "dist/index.js", + "scripts": { + "build": "tsc", + "clean": "rimraf dist/", + "start": "node dist/index.js", + "lint": "eslint . --ext .ts", + "lint:fix": "eslint . --ext .ts --fix" + }, + "dependencies": { + "@hashgraph/json-rpc-relay": "file:../relay", + "@koa/cors": "^4.0.0", + "koa": "^2.14.2", + "koa-bodyparser": "^4.4.1", + "koa-router": "^12.0.0", + "pino": "^8.15.0", + "pino-pretty": "^10.2.0", + "prom-client": "^14.2.0" + }, + "devDependencies": { + "@types/koa": "^2.13.8", + "@types/koa__cors": "^4.0.0", + "@types/koa-bodyparser": "^4.3.10", + "@types/koa-router": "^7.4.4", + "@types/node": "^20.5.7", + "@typescript-eslint/eslint-plugin": "^6.5.0", + "@typescript-eslint/parser": "^6.5.0", + "eslint": "^8.48.0", + "rimraf": "^5.0.1", + "typescript": "^5.2.2" + } +} diff --git a/packages/http-explorer-server/tsconfig.json b/packages/http-explorer-server/tsconfig.json new file mode 100644 index 0000000000..22cd79da81 --- /dev/null +++ b/packages/http-explorer-server/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "composite": true, + "target": "es6", + "lib": [ + "es6" + ], + "module": "commonjs", + "rootDir": "src/", + "moduleResolution": "node", + "outDir": "./dist", + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "forceConsistentCasingInFileNames": true, + "noImplicitAny": false, + "declaration": true, + "strict": true, + "sourceMap": true + }, + "include": [ + "src" + ] +}