Skip to content

Commit

Permalink
fix: fallback to public rpcs (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
sakulstra authored Nov 21, 2024
1 parent 67a0431 commit 8198f9a
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
25 changes: 25 additions & 0 deletions dist/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -23205,6 +23205,21 @@ var ChainId = {
zksync: zksync.id
};

// src/public.ts
var publicRPCs = {
[ChainId.mainnet]: "https://eth.llamarpc.com",
[ChainId.polygon]: "https://polygon.llamarpc.com",
[ChainId.arbitrum]: "https://polygon.llamarpc.com",
[ChainId.base]: "https://base.llamarpc.com",
[ChainId.bnb]: "https://binance.llamarpc.com",
[ChainId.metis]: "https://andromeda.metis.io/?owner=1088",
[ChainId.gnosis]: "https://rpc.ankr.com/gnosis",
[ChainId.scroll]: "https://rpc.scroll.io",
[ChainId.zksync]: "https://mainnet.era.zksync.io",
[ChainId.fantom]: "https://rpc.ftm.tools",
[ChainId.avalanche]: "https://api.avax.network/ext/bc/C/rpc"
};

// src/lib.ts
Object.values(ChainId).filter(
(id) => networkMap[id]
Expand Down Expand Up @@ -23240,6 +23255,12 @@ function getAlchemyRPC(chainId, alchemyKey2) {
}
return `https://${alchemyId}.g.alchemy.com/v2/${alchemyKey2}`;
}
function getPublicRpc(chainId) {
const publicRpc = publicRPCs[chainId];
if (!publicRpc)
throw new Error(`No default public rpc for '${chainId}' configured.`);
return publicRpc;
}
var getRPCUrl = (chainId, options) => {
if (!Object.values(ChainId).includes(chainId)) {
throw new Error(
Expand All @@ -23256,6 +23277,10 @@ var getRPCUrl = (chainId, options) => {
} catch (e) {
}
}
try {
return getPublicRpc(chainId);
} catch (e) {
}
};

// src/action.ts
Expand Down
25 changes: 25 additions & 0 deletions dist/action.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23203,6 +23203,21 @@ var ChainId = {
zksync: zksync.id
};

// src/public.ts
var publicRPCs = {
[ChainId.mainnet]: "https://eth.llamarpc.com",
[ChainId.polygon]: "https://polygon.llamarpc.com",
[ChainId.arbitrum]: "https://polygon.llamarpc.com",
[ChainId.base]: "https://base.llamarpc.com",
[ChainId.bnb]: "https://binance.llamarpc.com",
[ChainId.metis]: "https://andromeda.metis.io/?owner=1088",
[ChainId.gnosis]: "https://rpc.ankr.com/gnosis",
[ChainId.scroll]: "https://rpc.scroll.io",
[ChainId.zksync]: "https://mainnet.era.zksync.io",
[ChainId.fantom]: "https://rpc.ftm.tools",
[ChainId.avalanche]: "https://api.avax.network/ext/bc/C/rpc"
};

// src/lib.ts
Object.values(ChainId).filter(
(id) => networkMap[id]
Expand Down Expand Up @@ -23238,6 +23253,12 @@ function getAlchemyRPC(chainId, alchemyKey2) {
}
return `https://${alchemyId}.g.alchemy.com/v2/${alchemyKey2}`;
}
function getPublicRpc(chainId) {
const publicRpc = publicRPCs[chainId];
if (!publicRpc)
throw new Error(`No default public rpc for '${chainId}' configured.`);
return publicRpc;
}
var getRPCUrl = (chainId, options) => {
if (!Object.values(ChainId).includes(chainId)) {
throw new Error(
Expand All @@ -23254,6 +23275,10 @@ var getRPCUrl = (chainId, options) => {
} catch (e) {
}
}
try {
return getPublicRpc(chainId);
} catch (e) {
}
};

// src/action.ts
Expand Down
11 changes: 11 additions & 0 deletions src/lib.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { networkMap } from "./alchemyIds";
import { ChainId, ChainList } from "./chainIds";
import { publicRPCs } from "./public";

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

Expand Down Expand Up @@ -53,6 +54,13 @@ export function getAlchemyRPC(chainId: SupportedChainIds, alchemyKey: string) {
return `https://${alchemyId}.g.alchemy.com/v2/${alchemyKey}`;
}

export function getPublicRpc(chainId: SupportedChainIds) {
const publicRpc = publicRPCs[chainId as keyof typeof publicRPCs];
if (!publicRpc)
throw new Error(`No default public rpc for '${chainId}' configured.`);
return publicRpc;
}

type GetRPCUrlOptions = {
alchemyKey?: string;
};
Expand Down Expand Up @@ -89,6 +97,9 @@ export const getRPCUrl = (
return getAlchemyRPC(chainId, options?.alchemyKey);
} catch (e) {}
}
try {
return getPublicRpc(chainId);
} catch (e) {}
};

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

export const publicRPCs = {
[ChainId.mainnet]: "https://eth.llamarpc.com",
[ChainId.polygon]: "https://polygon.llamarpc.com",
[ChainId.arbitrum]: "https://polygon.llamarpc.com",
[ChainId.base]: "https://base.llamarpc.com",
[ChainId.bnb]: "https://binance.llamarpc.com",
[ChainId.metis]: "https://andromeda.metis.io/?owner=1088",
[ChainId.gnosis]: "https://rpc.ankr.com/gnosis",
[ChainId.scroll]: "https://rpc.scroll.io",
[ChainId.zksync]: "https://mainnet.era.zksync.io",
[ChainId.fantom]: "https://rpc.ftm.tools",
[ChainId.avalanche]: "https://api.avax.network/ext/bc/C/rpc",
} as const;

0 comments on commit 8198f9a

Please sign in to comment.