Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Creates new package for rest api explorer endpoints #3380

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
```
29 changes: 29 additions & 0 deletions packages/http-explorer-server/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*-
*
* Hedera JSON RPC Relay
*
* Copyright (C) 2025 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

import Koa from 'koa';

import { TokenRoutes } from './src/routes';

const app = new Koa();

app.use(TokenRoutes.routes());

export default app;
26 changes: 26 additions & 0 deletions packages/http-explorer-server/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*-
*
* Hedera JSON RPC Relay
*
* Copyright (C) 2025 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import app from './app';

function main() {
app.listen(3000);
}

main();
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"
}
}
19 changes: 19 additions & 0 deletions packages/http-explorer-server/src/config/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*-
*
* Hedera JSON RPC Relay
*
* Copyright (C) 2025 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*-
*
* Hedera JSON RPC Relay
*
* Copyright (C) 2025 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
19 changes: 19 additions & 0 deletions packages/http-explorer-server/src/middleware/validator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*-
*
* Hedera JSON RPC Relay
*
* Copyright (C) 2025 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
20 changes: 20 additions & 0 deletions packages/http-explorer-server/src/routes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*-
*
* Hedera JSON RPC Relay
*
* Copyright (C) 2025 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
export { TokenRoutes } from './tokenRoutes';
21 changes: 21 additions & 0 deletions packages/http-explorer-server/src/routes/tokenRoutes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*-
*
* Hedera JSON RPC Relay
*
* Copyright (C) 2025 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

class TokenRoutes {}
19 changes: 19 additions & 0 deletions packages/http-explorer-server/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*-
*
* Hedera JSON RPC Relay
*
* Copyright (C) 2025 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
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"
]
}
Loading