Skip to content

Commit

Permalink
feat: 🎉 begin web3-rpc-provider
Browse files Browse the repository at this point in the history
  • Loading branch information
xxamxx committed Sep 13, 2024
1 parent b05155b commit 737dc50
Show file tree
Hide file tree
Showing 20 changed files with 5,960 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
**/.vscode
**/.git
**/.gitignore
**/docker-compose*
**/Dockerfile*
**/.env
**/.aws
**/.editorconfig
**/*.md
**/LICENSE
**/node_modules/
**/*.log
**/dist
**/coverage
8 changes: 8 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"@typescript-eslint/no-misused-promises": [
"error",
{
"checksVoidReturn": false
}
]
}
37 changes: 37 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
vendor/

# Directories for AIR
tmp

# docs
docs/swagger.*

__debug_*

local*.yaml

# Node.js
node_modules/
.audit
.clinic
.npmrc
coverage/
dist/

__pycache__/

.env
12 changes: 12 additions & 0 deletions .swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"jsc": {
"parser": {
"syntax": "typescript"
},
"target": "es2016"
},
"module": {
"type": "commonjs"
},
"sourceMaps": true
}
49 changes: 49 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# syntax=docker/dockerfile:1

## 基础镜像,用于安装基础的依赖软件
FROM node:20.17.0-alpine as base

# 添加 Chromium 官方源
RUN echo "@edge http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories \
&& echo "@edgecommunity http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories

# 安装 Chromium 浏览器
RUN apk add --no-cache \
chromium

# 清理缓存,减小镜像大小
RUN rm -rf /var/cache/apk/*

# 设置环境变量,确保可以通过 Puppeteer 或类似工具使用 Chromium
ENV CHROME_BIN=/usr/bin/chromium-browser \
CHROME_PATH=/usr/lib/chromium/ \
CHROMIUM_FLAGS="--disable-software-rasterizer --disable-dev-shm-usage"


## 项目依赖包镜像
FROM base as deps
# 启用 pnpm
ENV PNPM_HOME="/pnpm" \
PATH="$PNPM_HOME:$PATH"
RUN corepack enable

# 安装项目依赖
WORKDIR /app
COPY package.json pnpm-lock.yaml ./
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile


## 项目代码镜像
FROM deps as app
LABEL MAINTAINER=xxamxx
WORKDIR /app

# 复制项目代码和 node_modules, 编译 typescript
COPY --from=deps /app/node_modules ./node_modules
COPY . /app
RUN npm run build

# 启动服务进程
EXPOSE 3000
ENV PUPPETEER_EXECUTABLE_PATH="/usr/bin/chromium"
CMD ["node", "./dist/bootstrap.js"]
97 changes: 97 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<div align="center" id="top">

&#xa0;

</div>
<h1 align="center">Web3 RPC Provider</h1>
<div align="center">
<img alt="NodeJS Version" src="https://img.shields.io/badge/node.js-%3E=_21.17.0-green.svg?style=flat-square"/>
&#xa0;
<a href="https://app.codacy.com/gh/DODOEX/web3-rpc-provider?utm_source=github.com&utm_medium=referral&utm_content=DODOEX/web3-rpc-provider&utm_campaign=Badge_Grade"><img alt="Codacy Badge" src="https://api.codacy.com/project/badge/Grade/77a87eb50ae94f3a9b5abde7bd46f7ec"/></a>
&#xa0;
<img alt="License Badge" src="https://img.shields.io/github/license/DODOEX/web3-rpc-provider.svg"/>
&#xa0;
<img alt="Release Badge" src="https://img.shields.io/github/release/DODOEX/web3-rpc-provider"/>
</div>
<br>

## :dart: Introduction

Web3 RPC Provider offers the apis of get the free endpoint, enabling clients to quickly access blockchain networks.

> [!NOTE]
> Works with [Web3 RPC Proxy](https://github.com/DODOEX/web3-rpc-provider) for optimal, stable, and latest block height access to blockchains.
<br>

## :rocket: Deployment

```bash
# Run the image
$ docker run -p 3000:3000 -d dodozoo/we3-rpc-provider:latest
```

## :bulb: Usage
The usage is straightforward, just make a request to the following apis.

Get the endpoint of multiple chains
```bash
curl --location --request GET 'http://localhost:3000/endpoints'
```

Query Parameters:

- `chains`: Required
The chains parameter allows specifying multiple chain ID values.

Get the endpoint of a single chain
```bash
curl --location --request GET 'http://localhost:3000/{{chain}}/endpoints'
```

- `chain`: Required
Represents the chain ID. fill it in to get the endpoint of the specified chain.

### Common Query Parameters:

- `sources`: Required
The sources parameter represents the source of the free endpoint. it can be filled in the class name of Picker in the [pickers](src/pickers) folder.

<br>

## :technologist: Development

### Starting Project
```bash
# Clone the project
$ git clone https://github.com/DODOEX/web3-rpc-provider

# Navigate to the project directory
$ cd web3-rpc-provider

# Install project dependencies
$ pnpm install

# Start the project
$ npm run start
```

## :busts_in_silhouette: Contribute
If you want to contribute to the Web3 RPC Provider project:

Fix issues: Find and fix issues in the project.
Write documentation: Improve and write relevant documentation for the project.
Write tests: Write and optimize test cases for the project.

If you want to show appreciation or support the continued development of the Web3 RPC Provider project, you can do so by:

Giving the project a GitHub Star. Supporting the project by donating a cup of tea.

<br>

## :memo: License
This project is under license from MIT. For more details, see [the LICENSE file](LICENSE).

&#xa0;

<div align="center"><a href="#top">Back to top</a></div>
37 changes: 37 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const fromPairs = pairs => pairs.reduce((res, [key, value]) => ({
...res,
[key]: value
}), {})

function moduleNameMapperFromTSPaths(tsconfig) {
return fromPairs(
Object.entries(tsconfig.compilerOptions.paths).map(([k, [v]]) => [
`^${k.replace(/\*/, "(.*)")}`,
`<rootDir>/${v.replace(/\*/, "$1")}`,
]),
)
}
const tsconfig = require("./tsconfig.json")
const moduleNameMapper = moduleNameMapperFromTSPaths(tsconfig)

module.exports = {
preset: 'jest-puppeteer',
testEnvironment: 'jest-environment-puppeteer',
testPathIgnorePatterns: [
'<rootDir>/node_modules/',
'<rootDir>/dist/',
'<rootDir>/test/fixtures',
],
coveragePathIgnorePatterns: [
'<rootDir>/test/',
],
setupFilesAfterEnv: [
'<rootDir>/jest.setup.ts'
],
reporters: [ 'default' ],
transform: {
'^.+\\.(t|j)s$': '@swc/jest',
},
verbose: false,
moduleNameMapper
};
3 changes: 3 additions & 0 deletions jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
jest.setTimeout(300000);
process.env.NODE_CONFIG_ENV = process.env.NODE_CONFIG_ENV ?? 'test';
process.env.NODE_ENV = process.env.NODE_ENV ?? 'test';
43 changes: 43 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "web3-rpc-provider",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node --no-warnings=ExperimentalWarning --loader ts-node/esm ./src/bootstrap.ts",
"start:debug": "node --inspect --no-warnings=ExperimentalWarning --loader ts-node/esm ./src/bootstrap.ts",
"start:prod": "node ./dist/bootstrap.js",
"test": "jest --forceExit --passWithNoTests",
"test:debug": "node --inspect-brk ./node_modules/jest/bin/jest.js --runInBand --debug --forceExit --passWithNoTests",
"test:watch": "jest --watch --passWithNoTests",
"test:coverage": "jest --coverage --passWithNoTests",
"clean": "rimraf build && rimraf dist",
"build": "swc src --strip-leading-paths --config-file .swcrc -d dist",
"build:watch": "swc src --strip-leading-paths --config-file .swcrc -d dist -w"
},
"keywords": [],
"author": "[email protected]<xxamxx>",
"license": "MIT",
"engines": {
"node": "v20.17.0"
},
"devDependencies": {
"@swc/cli": "^0.4.0",
"@swc/core": "^1.7.23",
"@swc/jest": "^0.2.36",
"@types/express": "^4.17.21",
"@types/jest": "^29.5.12",
"@types/node": "^20.16.3",
"expect-puppeteer": "^10.1.0",
"jest": "^29.7.0",
"jest-environment-puppeteer": "^10.1.0",
"jest-puppeteer": "^10.1.0",
"rimraf": "^6.0.1",
"ts-node": "^10.9.2",
"typescript": "^5.5.4"
},
"dependencies": {
"express": "^4.19.2",
"puppeteer-core": "^23.2.1"
}
}
Loading

0 comments on commit 737dc50

Please sign in to comment.