UNPKG

@molecularlabs/nucleus-frontend

Version:
74 lines 1.62 kB
import { erc20Abi } from "viem"; import { getClient } from "../lib/client"; const getErc20Balance = async ({ chainId, tokenAddress, userAddress }) => { const client = await getClient(chainId); const balance = await client.readContract({ abi: erc20Abi, address: tokenAddress, functionName: "balanceOf", args: [userAddress] }); return balance; }; const getErc20Decimals = async ({ chainId, tokenAddress }) => { const client = await getClient(chainId); const balance = await client.readContract({ abi: erc20Abi, address: tokenAddress, functionName: "decimals" }); return balance; }; const getErc20Allowance = async ({ chainId, tokenAddress, userAddress, spenderAddress }) => { const client = await getClient(chainId); const allowance = await client.readContract({ abi: erc20Abi, address: tokenAddress, functionName: "allowance", args: [userAddress, spenderAddress] }); return allowance; }; const getErc20AllowanceWithDecimals = async ({ chainId, tokenAddress, userAddress, spenderAddress }) => { const client = await getClient(chainId); const allowance = await client.multicall({ contracts: [ { abi: erc20Abi, address: tokenAddress, functionName: "allowance", args: [userAddress, spenderAddress] }, { abi: erc20Abi, address: tokenAddress, functionName: "decimals" } ] }); return allowance; }; export { getErc20Allowance, getErc20AllowanceWithDecimals, getErc20Balance, getErc20Decimals }; //# sourceMappingURL=erc20.mjs.map