Files
sre-03-token-vendor/packages/nextjs/utils/scaffold-eth/priceInWei.ts
2026-01-12 10:42:14 +07:00

17 lines
420 B
TypeScript

import { parseEther } from "viem";
export function multiplyTo1e18(tokens: string | bigint) {
try {
return parseEther(tokens.toString());
} catch (err) {
// wrong tokens value
return 0n;
}
}
export function getTokenPrice(tokens: string | bigint, tokensPerEth?: bigint) {
const tokensMultiplied = multiplyTo1e18(tokens);
return tokensPerEth ? tokensMultiplied / tokensPerEth : tokensMultiplied;
}