Initial commit with 🏗️ create-eth @ 2.0.4
This commit is contained in:
16
packages/nextjs/utils/scaffold-eth/priceInWei.ts
Normal file
16
packages/nextjs/utils/scaffold-eth/priceInWei.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user