import { ethers } from 'ethers'; /** * * @param {ethers.providers.Web3Provider} provider * @returns */ export const requestChainId = async (provider) => { const { chainId } = await provider.getNetwork(); return parseInt(chainId); }; /** * * @returns */ export const requestAccounts = async () => { if ((window as any).ethereum === undefined) return []; const result = await (window as any).ethereum.request({ method: 'eth_accounts', }); return result; }; /** * * @param {ethers.providers.Web3Provider} provider * @returns {float} */ export const requestBalance = async (provider, account) => { return parseFloat( ethers.utils.formatEther(await provider.getBalance(account)) ); };