@intuweb3/sdk
Version:
INTU SDK - Modern blockchain interaction toolkit
56 lines • 1.7 kB
JavaScript
import { ethers } from "ethers";
import { loadJson, JSON_PATHS } from "../utils/json-imports.js";
let chainListData = null;
(async () => {
try {
chainListData = await loadJson(JSON_PATHS.CHAIN_LIST);
}
catch (error) {
console.error("Failed to load chain list data:", error);
}
})();
const getChainList = () => {
if (!chainListData) {
throw new Error("Chain list data is not loaded yet. This should not happen.");
}
return chainListData;
};
export const getProviderForChain = (chainId) => {
const chainIdStr = chainId.toString();
const chainList = getChainList();
const chainInfo = chainList[chainIdStr];
if (!chainInfo) {
throw new Error(`Unsupported chainId: ${chainId}. This chain is not in our RPC list.`);
}
return new ethers.providers.JsonRpcProvider(chainInfo.r);
};
export const getChainInfo = (chainId) => {
const chainIdStr = chainId.toString();
const chainList = getChainList();
const chainInfo = chainList[chainIdStr];
if (!chainInfo) {
throw new Error(`Unsupported chainId: ${chainId}`);
}
return chainInfo;
};
export const getRpcUrl = (chainId) => {
const chainInfo = getChainInfo(chainId);
return chainInfo.r;
};
export const getSupportedChainIds = () => {
const chainList = getChainList();
return Object.keys(chainList);
};
export const isChainSupported = (chainId) => {
const chainIdStr = chainId.toString();
const chainList = getChainList();
return chainIdStr in chainList;
};
export default {
getProviderForChain,
getChainInfo,
getRpcUrl,
getSupportedChainIds,
isChainSupported,
};
//# sourceMappingURL=chainList.js.map