@keplr-ewallet/ewallet-sdk-eth
Version:
41 lines • 1.48 kB
JavaScript
import { toHex } from "viem";
import { v4 as uuidv4 } from "uuid";
import { initEWalletEIP1193Provider, } from "../provider";
import { DEFAULT_CHAIN_ID, SUPPORTED_CHAINS, TESTNET_CHAINS, } from "../chains";
export async function getEthereumProvider() {
var _a;
if (this.provider !== null) {
return this.provider;
}
let chains = SUPPORTED_CHAINS;
if (this.useTestnet) {
chains = [...chains, ...TESTNET_CHAINS];
}
const activeChain = (_a = chains.find((chain) => chain.id === DEFAULT_CHAIN_ID)) !== null && _a !== void 0 ? _a : chains[0];
const addEthereumChains = [
activeChain,
...chains.filter((chain) => chain.id !== DEFAULT_CHAIN_ID),
].map((chain) => {
var _a;
return ({
chainId: toHex(chain.id),
chainName: chain.name,
rpcUrls: chain.rpcUrls.default.http,
nativeCurrency: chain.nativeCurrency,
blockExplorerUrls: ((_a = chain.blockExplorers) === null || _a === void 0 ? void 0 : _a.default.url)
? [chain.blockExplorers.default.url]
: [],
});
});
this.provider = await initEWalletEIP1193Provider({
id: uuidv4(),
signer: {
sign: this.makeSignature,
getAddress: this.getAddress,
},
chains: addEthereumChains,
skipChainValidation: true,
});
return this.provider;
}
//# sourceMappingURL=get_ethereum_provider.js.map