Skip to content

Commit

Permalink
Creates new package for rest api explorer endpoints
Browse files Browse the repository at this point in the history
Signed-off-by: Konstantina Blazhukova <[email protected]>
  • Loading branch information
konstantinabl committed Jan 13, 2025
1 parent 11e1f1e commit 7f366e5
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 0 deletions.
84 changes: 84 additions & 0 deletions packages/http-explorer-server/README.md
Original file line number Diff line number Diff line change
@@ -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
```
35 changes: 35 additions & 0 deletions packages/http-explorer-server/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
23 changes: 23 additions & 0 deletions packages/http-explorer-server/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
]
}

0 comments on commit 7f366e5

Please sign in to comment.