Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Destiner committed Mar 20, 2024
0 parents commit 722463e
Show file tree
Hide file tree
Showing 11 changed files with 395 additions and 0 deletions.
49 changes: 49 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"env": {
"es2022": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:import/recommended",
"plugin:import/typescript",
"plugin:@typescript-eslint/recommended"
],
"parserOptions": {
"parser": "@typescript-eslint/parser",
"ecmaVersion": 2022,
"sourceType": "module"
},
"plugins": ["import"],
"rules": {
"import/first": "error",
"import/exports-last": "error",
"import/newline-after-import": "error",
"import/prefer-default-export": "error",
"import/group-exports": "error",
"import/no-duplicates": "error",
"import/no-amd": "error",
"import/no-commonjs": "error",
"import/order": [
"error",
{
"newlines-between": "always",
"alphabetize": {
"order": "asc"
}
}
],
"import/no-unused-modules": "error",
"import/no-mutable-exports": "error",
"import/no-extraneous-dependencies": [
"error",
{ "devDependencies": ["src/**/*.test.ts"] }
],
"@typescript-eslint/explicit-function-return-type": "error"
},
"settings": {
"import/resolver": {
"typescript": {}
}
}
}
34 changes: 34 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: CI

on:
push:
branches: main
pull_request:
branches: main

jobs:
run:
name: Run
runs-on: ubuntu-latest

strategy:
fail-fast: false

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Bun
uses: oven-sh/setup-bun@v1

- name: Clean install
run: bun install

- name: Lint
run: bun run lint

- name: Build
run: bun run build

- name: Test
run: bun run test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
dist/
3 changes: 3 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# evm-providers

EVM JSON-RPC Provider Registry

- Fully typed
- 20+ providers
- Most EVM chains
- Non-standard providers (e.g. bundlers and paymasters)

## Installation

```
bun i evm-providers
# or
npm i evm-providers
# or
yarn add evm-providers
```

## Usage

```ts
import { alchemy } from 'evm-providers';

const url = alchemy(1, '<your-alchemy-key>');
// https://eth-mainnet.g.alchemy.com/v2/<your-alchemy-key>
```

With [viem](https://github.com/wagmi-dev/viem):

```ts
import { createPublicClient, http } from 'viem';
import { mainnet } from 'viem/chains';
import { alchemy } from 'evm-providers';

const client = createPublicClient({
chain: mainnet,
transport: http(alchemy(mainnet.id, '<your-alchemy-key>')),
});
```

## Chains

- Ethereum
- Sepolia
- Polygon
- Polygon Mumbai
- Polygon Amoy
- Arbitrum
- Arbitrum Sepolia
- Optimism
- Optimism Sepolia
- Polygon ZKEVM
- Polygon ZKEVM Testnet
- Base
- Base Sepolia
- Astar

## Providers

- Alchemy

```
```
Binary file added bun.lockb
Binary file not shown.
42 changes: 42 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "evm-providers",
"version": "0.1.0",
"description": "EVM JSON-RPC Provider Registry",
"author": {
"name": "Timur Badretdinov",
"url": "https://github.com/Destiner"
},
"keywords": [
"viem",
"ethereum"
],
"license": "MIT",
"repository": {
"type": "git",
"url": "git://github.com/Destiner/ethcall.git"
},
"type": "module",
"main": "./dist/index.js",
"exports": "./dist/index.js",
"scripts": {
"test": "vitest run",
"lint": "npm run lint:eslint && npm run lint:prettier",
"lint:eslint": "eslint \"src/**/*.ts\"",
"lint:prettier": "prettier -c \"src/**/*.{json,js,ts}\"",
"build": "tsc --p tsconfig.build.json",
"prepack": "npm run build"
},
"devDependencies": {
"@types/bun": "latest",
"@typescript-eslint/eslint-plugin": "^7.3.1",
"eslint": "^8.57.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.1",
"prettier": "^3.2.5",
"typescript": "5.4.3",
"vitest": "^1.4.0"
},
"dependencies": {
"viem": "^2.8.16"
}
}
13 changes: 13 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { describe, expect, it } from 'vitest';

import { alchemy } from './index.js';

// Don't worry, those are not valid :)
const ALCHEMY_KEY = 'qi_uQW4FZK5uCDSWcj3XYQdUW_jHbSow';

describe('alchemy', () => {
it('should return the correct URL for Ethereum', () => {
const url = alchemy(1, ALCHEMY_KEY);
expect(url).toBe(`https://eth-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}`);
});
});
146 changes: 146 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
const ETHEREUM = 1;
const GOERLI = 5;
const SEPOLIA = 11155111;
const ARBITRUM = 42161;
// const ARBITRUM_NOVA = 42170;
const ARBITRUM_SEPOLIA = 421614;
const OPTIMISM = 10;
const OPTIMISM_SEPOLIA = 11155420;
const BASE = 8453;
const BASE_SEPOLIA = 84532;
const POLYGON = 137;
const POLYGON_MUMBAI = 80001;
const POLYGON_AMOY = 80002;
const POLYGON_ZKEVM = 1101;
const POLYGON_ZKEVM_TESTNET = 1442;
const AVALANCHE_C = 43114;
const AVALANCHE_FUJI = 43113;
const CELO = 42220;
const CELO_ALFAJORES = 44787;
// const ZORA = 7777777;
// const ZORA_SEPOLIA = 999999999;
const LINEA = 59144;
const LINEA_GOERLI = 59140;
const BLAST = 81457;
const BLAST_SEPOLIA = 168587773;
const PALM = 11297108109;
const PALM_TESTNET = 11297108099;
const ASTAR = 592;

type AlchemyChain =
| typeof ETHEREUM
| typeof SEPOLIA
| typeof POLYGON
| typeof POLYGON_MUMBAI
| typeof POLYGON_AMOY
| typeof ARBITRUM
| typeof ARBITRUM_SEPOLIA
| typeof OPTIMISM
| typeof OPTIMISM_SEPOLIA
| typeof POLYGON_ZKEVM
| typeof POLYGON_ZKEVM_TESTNET
| typeof BASE
| typeof BASE_SEPOLIA
| typeof ASTAR;

type InfuraChain =
| typeof ETHEREUM
| typeof GOERLI
| typeof SEPOLIA
| typeof LINEA
| typeof LINEA_GOERLI
| typeof POLYGON
| typeof POLYGON_MUMBAI
| typeof POLYGON_AMOY
| typeof BLAST
| typeof BLAST_SEPOLIA
| typeof OPTIMISM
| typeof OPTIMISM_SEPOLIA
| typeof ARBITRUM
| typeof ARBITRUM_SEPOLIA
| typeof PALM
| typeof PALM_TESTNET
| typeof AVALANCHE_C
| typeof AVALANCHE_FUJI
| typeof CELO
| typeof CELO_ALFAJORES;

function alchemy(chain: AlchemyChain, key: string): string {
switch (chain) {
case ETHEREUM:
return `https://eth-mainnet.g.alchemy.com/v2/${key}`;
case SEPOLIA:
return `https://eth-sepolia.g.alchemy.com/v2/${key}`;
case POLYGON:
return `https://polygon-mainnet.g.alchemy.com/v2/${key}`;
case POLYGON_MUMBAI:
return `https://polygon-mumbai.g.alchemy.com/v2/${key}`;
case POLYGON_AMOY:
return `https://polygon-amoy.g.alchemy.com/v2/${key}`;
case ARBITRUM:
return `https://arb-mainnet.g.alchemy.com/v2/${key}`;
case ARBITRUM_SEPOLIA:
return `https://arb-sepolia.g.alchemy.com/v2/${key}`;
case OPTIMISM:
return `https://opt-mainnet.g.alchemy.com/v2/${key}`;
case OPTIMISM_SEPOLIA:
return `https://opt-sepolia.g.alchemy.com/v2/${key}`;
case POLYGON_ZKEVM:
return `https://polygonzkevm-mainnet.g.alchemy.com/v2/${key}`;
case POLYGON_ZKEVM_TESTNET:
return `https://polygonzkevm-testnet.g.alchemy.com/v2/${key}`;
case BASE:
return `https://base-mainnet.g.alchemy.com/v2/${key}`;
case BASE_SEPOLIA:
return `https://base-sepolia.g.alchemy.com/v2/${key}`;
case ASTAR:
return `https://astar-mainnet.g.alchemy.com/v2/${key}`;
}
}

function infura(chain: InfuraChain, key: string): string {
switch (chain) {
case ETHEREUM:
return `https://mainnet.infura.io/v3/${key}`;
case GOERLI:
return `https://goerli.infura.io/v3/${key}`;
case SEPOLIA:
return `https://sepolia.infura.io/v3/${key}`;
case LINEA:
return `https://linea-mainnet.infura.io/v3/${key}`;
case LINEA_GOERLI:
return `https://linea-goerli.infura.io/v3/${key}`;
case POLYGON:
return `https://polygon-mainnet.infura.io/v3/${key}`;
case POLYGON_MUMBAI:
return `https://polygon-mumbai.infura.io/v3/${key}`;
case POLYGON_AMOY:
return `https://polygon-amoy.infura.io/v3/${key}`;
case BLAST:
return `https://blast-mainnet.infura.io/v3/${key}`;
case BLAST_SEPOLIA:
return `https://blast-sepolia.infura.io/v3/${key}`;
case OPTIMISM:
return `https://optimism-mainnet.infura.io/v3/${key}`;
case OPTIMISM_SEPOLIA:
return `https://optimism-sepolia.infura.io/v3/${key}`;
case ARBITRUM:
return `https://arbitrum-mainnet.infura.io/v3/${key}`;
case ARBITRUM_SEPOLIA:
return `https://arbitrum-sepolia.infura.io/v3/${key}`;
case PALM:
return `https://palm-mainnet.infura.io/v3/${key}`;
case PALM_TESTNET:
return `https://palm-testnet.infura.io/v3/${key}`;
case AVALANCHE_C:
return `https://avalanche-mainnet.infura.io/v3/${key}`;
case AVALANCHE_FUJI:
return `https://avalanche-fuji.infura.io/v3/${key}`;
case CELO:
return `https://celo-mainnet.infura.io/v3/${key}`;
case CELO_ALFAJORES:
return `https://celo-alfajores.infura.io/v3/${key}`;
}
}

export { alchemy, infura };
4 changes: 4 additions & 0 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"exclude": ["src/**/*.test.ts"]
}
Loading

0 comments on commit 722463e

Please sign in to comment.