Skip to content

Commit

Permalink
cleanup: clean up a bit of the mess i created
Browse files Browse the repository at this point in the history
  • Loading branch information
sakulstra committed Nov 21, 2024
1 parent 28b2950 commit 2a6b23a
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 21 deletions.
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
# BGD RPC ENV

When working on multichain projects it is a tedious task to setup private RPCs and managing them in your local environment or github actions.
This repository is a suite of tools to streamline the handling of RPC environment variables, by automating the creation and injection of environment variables following a common [naming scheme](./src/lib.test.ts).

## NodeJS: `@bgd-labs/rpc-env`

[![NPM Version](https://img.shields.io/npm/v/%40bgd-labs%2Frpc-env)](https://www.npmjs.com/package/@bgd-labs/rpc-env)

### Usage
### Usage as a library

```typescript
import { getRPCUrl, ChainId } from "@bgd-labs/rpc-env";

const url = getRPCUrl(ChainId.mainnet, "[YOUR_ALCHEMY_KEY]");
// will fetch the rpc based on a opinionated priorization and does not error if no rpc is found
// 1. checks if `RPC_MAINNET` is set, otherwise
// 2. checks if alchemy key was provided & if alchemy supports the network, otherwise
// 3. checks if a public rpc is configured
const url = getRPCUrl(ChainId.mainnet, { alchemyKey?: "[YOUR_ALCHEMY_KEY]" });

// alternatively you can use the explicit getters, which will throw if no rpc is found
const url = getExplicitRPC(ChainId.mainnet);
const url = getAlchemyRPC(ChainId.mainnet, alchemyKey);
const url = getPublicRpc(ChainId.mainnet);
```

### Usage as cli

The cli will emit explicit rps and a foundry.toml configuration for each network.

```
export ALCHEMY_API_KEY=<> && npx @bgd-labs/rpc-env
```

## Action: `action-rpc-env`
Expand Down
2 changes: 1 addition & 1 deletion dist/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -23205,7 +23205,7 @@ var ChainId = {
zksync: zksync.id
};

// src/public.ts
// src/publicRPCs.ts
var publicRPCs = {
[ChainId.mainnet]: "https://eth.llamarpc.com",
[ChainId.polygon]: "https://polygon.llamarpc.com",
Expand Down
2 changes: 1 addition & 1 deletion dist/action.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23203,7 +23203,7 @@ var ChainId = {
zksync: zksync.id
};

// src/public.ts
// src/publicRPCs.ts
var publicRPCs = {
[ChainId.mainnet]: "https://eth.llamarpc.com",
[ChainId.polygon]: "https://polygon.llamarpc.com",
Expand Down
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 6 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@
"publishConfig": {
"access": "public"
},
"sideEffects": false,
"scripts": {
"build": "tsup",
"test": "vitest",
"format": "biome check --write",
"prepublishOnly": "npm run build"
},
"files": [
"src/*.ts",
"dist/lib*",
"dist/cli*"
],
"files": ["src/*.ts", "dist/lib*", "dist/cli*"],
"bin": "./dist/cli.js",
"main": "./dist/lib.js",
"module": "./dist/lib.mjs",
Expand All @@ -42,22 +39,16 @@
"tsup": "^8.3.5",
"typescript": "^5.6.3",
"viem": "^2.21.48",
"vitest": "^2.1.4"
"vitest": "^2.1.4",
"dotenv": "^16.4.5"
},
"tsup": {
"entry": [
"src/action.ts",
"src/lib.ts",
"src/cli.ts"
],
"entry": ["src/action.ts", "src/lib.ts", "src/cli.ts"],
"splitting": false,
"sourcemap": false,
"clean": true,
"dts": true,
"treeshake": true,
"format": [
"esm",
"cjs"
]
"format": ["esm", "cjs"]
}
}
1 change: 1 addition & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env node
import "dotenv/config";
import { ChainId, getNetworkEnv, getRPCUrl } from "./lib";

(function print() {
Expand Down
4 changes: 2 additions & 2 deletions src/lib.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { networkMap } from "./alchemyIds";
import { ChainId, ChainList } from "./chainIds";
import { publicRPCs } from "./public";
import { publicRPCs } from "./publicRPCs";

type SupportedChainIds = (typeof ChainId)[keyof typeof ChainId];

Expand Down Expand Up @@ -102,4 +102,4 @@ export const getRPCUrl = (
} catch (e) {}
};

export { ChainId, ChainList };
export { ChainId, ChainList, type SupportedChainIds };
4 changes: 4 additions & 0 deletions src/public.ts → src/publicRPCs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { ChainId } from "./chainIds";

/**
* A manually maintained list of public rpcs.
* These should only be used for prs coming from forks, which should not access secrets like the alchemy api key.
*/
export const publicRPCs = {
[ChainId.mainnet]: "https://eth.llamarpc.com",
[ChainId.polygon]: "https://polygon.llamarpc.com",
Expand Down

0 comments on commit 2a6b23a

Please sign in to comment.