-
-
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
Nick
committed
Feb 20, 2022
1 parent
1bab041
commit 2384dfd
Showing
37 changed files
with
7,198 additions
and
1 deletion.
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,4 @@ | ||
node_modules | ||
build | ||
docker | ||
bin |
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,33 @@ | ||
{ | ||
"env": { | ||
"node": true | ||
}, | ||
"rules": { | ||
"semi": [2, "always"], | ||
"comma-dangle": ["error", { | ||
"arrays": "always-multiline", | ||
"functions": "always-multiline", | ||
"objects": "always-multiline" | ||
}], | ||
"prefer-const": "error", | ||
"quotes": "off", | ||
"no-self-compare": "off", | ||
"@typescript-eslint/no-var-requires": "off", | ||
"@typescript-eslint/no-explicit-any": "off", | ||
"@typescript-eslint/no-inferrable-types": "off", | ||
"@typescript-eslint/explicit-module-boundary-types": "off", | ||
"@typescript-eslint/no-extra-semi": "off", | ||
"@typescript-eslint/no-unused-vars": "error", | ||
"@typescript-eslint/ban-ts-comment": "off" | ||
}, | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaVersion": 9 | ||
}, | ||
"plugins": ["@typescript-eslint"], | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended" | ||
] | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,27 @@ | ||
name: Build Package | ||
|
||
on: | ||
push: | ||
tags: | ||
- '*.*.*' | ||
|
||
jobs: | ||
build: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ ubuntu-latest ] | ||
node: [ 16 ] | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Setup Node | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: ${{ matrix.node }} | ||
check-latest: true | ||
registry-url: 'https://npm.pkg.github.com' | ||
- name: Install Dependencies | ||
run: yarn | ||
- name: Publish Package | ||
run: npm publish |
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,74 @@ | ||
name: Test and Lint | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ ubuntu-latest ] | ||
node: [ 16 ] | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@master | ||
- name: Setup node env | ||
uses: actions/[email protected] | ||
with: | ||
node-version: ${{ matrix.node }} | ||
check-latest: true | ||
registry-url: 'https://npm.pkg.github.com' | ||
always-auth: true | ||
scope: '@web3xlabs' | ||
- name: Get yarn cache directory path | ||
id: yarn-cache-dir-path | ||
run: echo "::set-output name=dir::$(yarn cache dir)" | ||
- name: Cache node_modules | ||
uses: actions/[email protected] | ||
id: yarn-cache | ||
with: | ||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | ||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-yarn- | ||
- name: Install dependencies | ||
run: yarn | ||
- name: Run Tests | ||
run: yarn test | ||
|
||
lint: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ ubuntu-latest ] | ||
node: [ 16 ] | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@master | ||
- name: Setup node env | ||
uses: actions/[email protected] | ||
with: | ||
node-version: ${{ matrix.node }} | ||
check-latest: true | ||
registry-url: 'https://npm.pkg.github.com' | ||
always-auth: true | ||
scope: '@web3xlabs' | ||
- name: Get yarn cache directory path | ||
id: yarn-cache-dir-path | ||
run: echo "::set-output name=dir::$(yarn cache dir)" | ||
- name: Cache node_modules | ||
uses: actions/[email protected] | ||
id: yarn-cache | ||
with: | ||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | ||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-yarn- | ||
- name: Install dependencies | ||
run: yarn | ||
- name: Run linter | ||
run: yarn lint |
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,4 @@ | ||
node_modules/ | ||
lib/ | ||
.idea/ | ||
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 @@ | ||
@OWNER:registry=https://npm.pkg.github.com |
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 @@ | ||
"@web3xlabs:registry" "https://npm.pkg.github.com" |
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 |
---|---|---|
@@ -1,2 +1,125 @@ | ||
# ethclients.js | ||
Collection of EVM-based client connectors | ||
|
||
[![Test and Lint](https://github.com/web3xlabs/ethclients.js/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/web3xlabs/ethclients.js/actions/workflows/ci.yml) | ||
|
||
Provides Smart Chain clients for JS bots. | ||
|
||
![](.github/web3x.png) | ||
|
||
A [Web3X](https://web3x.net) Product | ||
|
||
### Installation | ||
|
||
#### Setup NPM installation from Github Packages | ||
This package is located on GitHub Packages. You will need to configure your project to install from this | ||
registry. | ||
|
||
See: [Installing a Package](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-npm-registry#installing-a-package) | ||
|
||
#### Add Package | ||
|
||
``` | ||
yarn add @web3xlabs/ethclients.js # Using Yarn | ||
npm install @web3xlabs/ethclients.js # Using NPM | ||
``` | ||
|
||
### Supported Clients | ||
* Ethereum - `ETHClient` | ||
* Binance - `BSCClient` | ||
* KuCoin - `KucoinClient` | ||
* Cronos - `CronosClient` | ||
* Avax - `AvaxClient` | ||
|
||
### Usage | ||
|
||
```typescript | ||
import { | ||
BSCClient, | ||
KucoinClient, | ||
ETHClient, | ||
CronosClient, | ||
AvaxClient, | ||
BaseClient | ||
} from '@web3xlabs/ethclients.js'; | ||
|
||
const client = new BSCClient([ | ||
// Endpoints list | ||
]); | ||
await client.connect(); | ||
|
||
console.log(await client.isConnected()); | ||
``` | ||
|
||
### Endpoints and Lists | ||
|
||
Each client instance accepts an `Array<string>` of RPC endpoints. These endpoints may be HTTP/S, or WS/S, and | ||
the client will determine the correct provider based on the endpoint passed in. | ||
|
||
It is a good idea to pass in multiple endpoints if possible, as the client driver will automatically failover | ||
to the next available endpoint if an error is encountered during a request. | ||
|
||
#### Public RPC Endpoints | ||
|
||
**Warning:** These endpoints are provided by the community without an uptime guarantee. These endpoints will often | ||
work for testing, but be aware of any latency or delay, and also be aware that they may stop working at any time. | ||
|
||
**Ethereum:** | ||
``` | ||
https://main-light.eth.linkpool.io | ||
wss://main-light.eth.linkpool.io/ws | ||
``` | ||
|
||
**Binance:** | ||
``` | ||
https://bsc-dataseed.binance.org/ | ||
https://bsc-dataseed1.defibit.io/ | ||
https://bsc-dataseed1.ninicoin.io/ | ||
wss://bsc-ws-node.nariox.org:443 | ||
``` | ||
|
||
**KuCoin:** | ||
``` | ||
https://rpc-mainnet.kcc.network/ | ||
``` | ||
|
||
**Cronos:** | ||
``` | ||
https://evm-cronos.org/ | ||
``` | ||
|
||
**Avax:** | ||
``` | ||
https://api.avax.network/ext/bc/C/rpc | ||
``` | ||
|
||
## Advanced | ||
|
||
Each client instance accepts an optional `endpoint: string` argument that will override | ||
the default endpoint for the client to connect to. | ||
|
||
Providing an endpoint that begins with `http://` or `https://` will automatically use the | ||
`HttpProvider` connection provider. Endpoints that begin with `ws://` or `wss://` will | ||
automatically use the `WebsocketProvider` connection provider. | ||
|
||
Each client also provides an endpoint list specific to that chain's public RPC endpoints. This | ||
list will be looped over 3 times during connection attempts, and if the current endpoint does | ||
not connect successfully, the next endpoint will be tried. | ||
|
||
```typescript | ||
import { ETHClient } from '@web3xlabs/ethclients.js'; | ||
|
||
const client = new ETHClient('https://invalid-rpc-url.com'); | ||
|
||
// Will log an error for the given endpoint then reconnect using a valid endpoint. | ||
await client.connect(); | ||
``` | ||
|
||
Providing no `endpoint` to the client will cause the client to attempt connection on the first | ||
endpoint in its list. If that endpoint fails, it will continue through the list as described. | ||
|
||
```typescript | ||
import { BSCClient } from '@web3xlabs/ethclients.js'; | ||
|
||
const client = new BSCClient(); // Will use first endpoint in list | ||
await client.connect(); | ||
``` |
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 @@ | ||
module.exports = require('./lib'); |
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,19 @@ | ||
module.exports = { | ||
"roots": [ | ||
"<rootDir>/tests", | ||
"<rootDir>/src", | ||
], | ||
"collectCoverageFrom": [ | ||
"src/**/*.ts", | ||
], | ||
"testMatch": [ | ||
"**/__tests__/**/*.+(ts|tsx|js)", | ||
"**/?(*.)+(spec|test).+(ts|tsx|js)", | ||
], | ||
"transform": { | ||
"^.+\\.(ts|tsx)$": "ts-jest", | ||
}, | ||
"moduleNameMapper": { | ||
"@ethclients/(.*)": "<rootDir>/src/$1", | ||
}, | ||
}; |
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,53 @@ | ||
{ | ||
"name": "@web3xlabs/ethclients.js", | ||
"version": "1.0.0", | ||
"description": "Collection of EVM-based client connectors", | ||
"main": "lib/index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/web3xlabs/ethclients.js.git" | ||
}, | ||
"scripts": { | ||
"test": "jest", | ||
"lint": "eslint . --ext .ts", | ||
"lint:fix": "eslint . --ext .ts --fix", | ||
"build": "tsc --project ./", | ||
"prestart": "npm run build", | ||
"start": "node .", | ||
"run": "node .", | ||
"prepare": "npm run build && ts-patch install -s" | ||
}, | ||
"keywords": [], | ||
"author": "Nick Wilging <[email protected]>", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@types/jest": "^26.0.24", | ||
"@types/jest-when": "^2.7.3", | ||
"@types/node": "^16.3.2", | ||
"@typescript-eslint/eslint-plugin": "^4.30.0", | ||
"@typescript-eslint/parser": "^4.30.0", | ||
"eslint": "^7.32.0", | ||
"jest": "^27.0.6", | ||
"jest-each": "^27.2.0", | ||
"jest-when": "^3.4.2", | ||
"ts-jest": "^27.0.5", | ||
"ts-node": "^10.2.1", | ||
"ts-patch": "^2.0.1", | ||
"typescript": "^4.4.3", | ||
"typescript-transform-paths": "^3.3.1", | ||
"web3-core": "^1.5.3" | ||
}, | ||
"dependencies": { | ||
"module-alias": "^2.2.2", | ||
"web3": "^1.5.3" | ||
}, | ||
"files": [ | ||
"lib/**/*" | ||
], | ||
"publishConfig": { | ||
"registry": "https://npm.pkg.github.com" | ||
}, | ||
"_moduleAliases": { | ||
"@ethclients": "lib" | ||
} | ||
} |
Oops, something went wrong.