Skip to content

Commit

Permalink
docs: 📝 Add docs for the library usage
Browse files Browse the repository at this point in the history
Signed-off-by: Jonas Strassel <info@jonas-strassel.de>
  • Loading branch information
boredland committed Nov 1, 2024
1 parent 1b4b76b commit ea7e027
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
32 changes: 22 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -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"
```
10 changes: 2 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
}
10 changes: 6 additions & 4 deletions src/lib.test.ts
Original file line number Diff line number Diff line change
@@ -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"`,
);
});
Expand Down

0 comments on commit ea7e027

Please sign in to comment.