Skip to content

Commit

Permalink
Small change to rpc url config
Browse files Browse the repository at this point in the history
  • Loading branch information
rkalis committed May 1, 2024
1 parent 8b25a2f commit 937f8cf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/chains/Chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface ChainOptions {
explorerUrl?: string;
etherscanCompatibleApiUrl?: string;
rpc?: {
main?: string;
main?: string | string[];
logs?: string;
free?: string;
};
Expand Down Expand Up @@ -88,9 +88,16 @@ export class Chain {
return this.options.rpc?.free ?? rpcUrl ?? this.getRpcUrl();
}

getRpcUrls(): string[] {
const baseRpcUrls =
getChain(this.chainId)?.rpc?.map((url) => url.replace('${INFURA_API_KEY}', INFURA_API_KEY)) ?? [];
const specifiedRpcUrls = [this.options.rpc?.main].flat().filter(Boolean);
const rpcOverrides = RPC_OVERRIDES[this.chainId] ? [RPC_OVERRIDES[this.chainId]] : [];
return [...rpcOverrides, ...specifiedRpcUrls, ...baseRpcUrls];
}

getRpcUrl(): string {
const defaultRpcUrl = getChain(this.chainId)?.rpc?.at(0)?.replace('${INFURA_API_KEY}', INFURA_API_KEY);
return RPC_OVERRIDES[this.chainId] ?? this.options.rpc?.main ?? defaultRpcUrl;
return this.getRpcUrls()[0];
}

getLogsRpcUrl(): string {
Expand Down
4 changes: 4 additions & 0 deletions lib/utils/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2232,6 +2232,10 @@ export const getChainRpcUrl = (chainId: number): string | undefined => {
return getChainConfig(chainId)?.getRpcUrl();
};

export const getChainRpcUrls = (chainId: number): string[] | undefined => {
return getChainConfig(chainId)?.getRpcUrls();
};

export const getChainLogsRpcUrl = (chainId: number): string | undefined => {
return getChainConfig(chainId)?.getLogsRpcUrl();
};
Expand Down

0 comments on commit 937f8cf

Please sign in to comment.