@xuxinlai2002/pns-js
Version:
A NPM package in Typescript for .Play Name Service
21 lines (17 loc) • 541 B
text/typescript
import { etherUnits } from '../../constants/unit.js'
import { type FormatUnitsErrorType, formatUnits } from './formatUnits.js'
export type FormatEtherErrorType = FormatUnitsErrorType
/**
* Converts numerical wei to a string representation of ether.
*
* - Docs: https://viem.sh/docs/utilities/formatEther.html
*
* @example
* import { formatEther } from 'viem'
*
* formatEther(1000000000000000000n)
* // '1'
*/
export function formatEther(wei: bigint, unit: 'wei' | 'gwei' = 'wei') {
return formatUnits(wei, etherUnits[unit])
}