-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
5,960 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"@typescript-eslint/no-misused-promises": [ | ||
"error", | ||
{ | ||
"checksVoidReturn": false | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<div align="center" id="top"> | ||
|
||
  | ||
|
||
</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"/> | ||
  | ||
<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> | ||
  | ||
<img alt="License Badge" src="https://img.shields.io/github/license/DODOEX/web3-rpc-provider.svg"/> | ||
  | ||
<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). | ||
|
||
  | ||
|
||
<div align="center"><a href="#top">Back to top</a></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
Oops, something went wrong.