diff --git a/README.md b/README.md index 998a23b..c347309 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,33 @@ -# Action: `action-rpc-env` +## NodeJS: `@bgd-labs/rpc-env` + +![NPM Version](https://img.shields.io/npm/v/%40bgd-labs%2Frpc-env) + +### Usage + +```typescript +import { getRPCUrl, ChainId } from "@bgd-labs/rpc-env"; + +const url = getRPCUrl(ChainId.mainnet, "[YOUR_ALCHEMY_KEY]"); +``` + +## Action: `action-rpc-env` This action iterates over the supported chain ids and sets the corresponding env var. -## Inputs +### Inputs -### `ALCHEMY_API_KEY` +#### `ALCHEMY_API_KEY` Alchemy API key If given, the action substitute missing RPC_URLs with one constructed from the given key. -### Usage +#### Usage -``` - - uses: bgd-labs/action-rpc-env@main - with: - ALCHEMY_API_KEY: ${{ secrets.ALCHEMY_API_KEY }} - env: - RPC_POLYGON: "https://rpc.polygon.com" +```yaml +- uses: bgd-labs/action-rpc-env@main + with: + ALCHEMY_API_KEY: ${{ secrets.ALCHEMY_API_KEY }} + env: + RPC_POLYGON: "https://rpc.polygon.com" ``` diff --git a/package.json b/package.json index 0af8ca2..76eb7b0 100644 --- a/package.json +++ b/package.json @@ -46,17 +46,11 @@ "vitest": "^2.1.3" }, "tsup": { - "entry": [ - "src/action.ts", - "src/lib.ts" - ], + "entry": ["src/action.ts", "src/lib.ts"], "splitting": false, "sourcemap": false, "clean": true, "dts": true, - "format": [ - "esm", - "cjs" - ] + "format": ["esm", "cjs"] } } diff --git a/src/lib.test.ts b/src/lib.test.ts index 9be9b4c..63868f7 100644 --- a/src/lib.test.ts +++ b/src/lib.test.ts @@ -1,21 +1,23 @@ import { describe } from "node:test"; import { expect, it } from "vitest"; -import { getRPCUrl } from "./lib"; +import { ChainId, getRPCUrl } from "./lib"; describe("lib", () => { it("should use env var if given", () => { process.env.RPC_MAINNET = "https://rpc.mainnet.com"; - expect(getRPCUrl(1)).toMatchInlineSnapshot(`"https://rpc.mainnet.com"`); + expect(getRPCUrl(ChainId.mainnet)).toMatchInlineSnapshot( + `"https://rpc.mainnet.com"`, + ); }); it("should return undefined if no env var is given and alchemy key not passed", () => { process.env.RPC_MAINNET = ""; - expect(getRPCUrl(1)).toBeUndefined(); + expect(getRPCUrl(ChainId.mainnet)).toBeUndefined(); }); it("should generate url if no env var is given and alchemy key is passed", () => { process.env.RPC_MAINNET = ""; - expect(getRPCUrl(1, "abc")).toMatchInlineSnapshot( + expect(getRPCUrl(ChainId.mainnet, "abc")).toMatchInlineSnapshot( `"https://eth-mainnet.g.alchemy.com/v2/abc"`, ); });