Skip to content
This repository was archived by the owner on Aug 30, 2022. It is now read-only.

Commit 7aab5d6

Browse files
authored
handle ws rpc urls & alias matic -> polygon mapping (#446)
1 parent 75d80d4 commit 7aab5d6

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

etc/sdk.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ export const ChainlinkVrf: Record<number, ChainlinkInfo>;
208208
// Warning: (ae-internal-missing-underscore) The name "ChainOrRpc" should be prefixed with an underscore because the declaration is marked as @internal
209209
//
210210
// @internal (undocumented)
211-
export type ChainOrRpc = "mumbai" | "polygon" | "rinkeby" | "goerli" | "mainnet" | "fantom" | "avalanche" | (string & {});
211+
export type ChainOrRpc = "mumbai" | "polygon" | "matic" | "rinkeby" | "goerli" | "mainnet" | "ethereum" | "fantom" | "avalanche" | (string & {});
212212

213213
// Warning: (ae-internal-missing-underscore) The name "CidWithFileName" should be prefixed with an underscore because the declaration is marked as @internal
214214
//

src/constants/urls.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@ export const PINATA_IPFS_URL = `https://api.pinata.cloud/pinning/pinFileToIPFS`;
2727
export type ChainOrRpc =
2828
| "mumbai"
2929
| "polygon"
30+
// common alias for `polygon`
31+
| "matic"
3032
| "rinkeby"
3133
| "goerli"
3234
| "mainnet"
35+
// common alias for `mainnet`
36+
| "ethereum"
3337
| "fantom"
3438
| "avalanche"
3539
// ideally we could use `https://${string}` notation here, but doing that causes anything that is a generic string to throw a type error => not worth the hassle for now
@@ -58,15 +62,17 @@ export function getProviderForNetwork(network: ChainOrRpc | SignerOrProvider) {
5862
case "goerli":
5963
return `https://eth-goerli.g.alchemy.com/v2/${DEFAULT_API_KEY}`;
6064
case "polygon":
65+
case "matic":
6166
return `https://polygon-mainnet.g.alchemy.com/v2/${DEFAULT_API_KEY}`;
62-
case "mainnet" || "ethereum":
67+
case "mainnet":
68+
case "ethereum":
6369
return `https://eth-mainnet.g.alchemy.com/v2/${DEFAULT_API_KEY}`;
6470
case "fantom":
6571
return "https://rpc.ftm.tools";
6672
case "avalanche":
6773
return "https://rpc.ankr.com/avalanche";
6874
default:
69-
if (network.startsWith("http")) {
75+
if (network.startsWith("http") || network.startsWith("ws")) {
7076
return network;
7177
} else {
7278
throw new Error(`Unrecognized chain name or RPC url: ${network}`);

0 commit comments

Comments
 (0)