README
Conversions
Utils to convert values between on-chain "base" and human-readable "display" units
Installation
$ yarn add @tokensoft/conversions
$ npm install @tokensoft/conversions
Usage
import { toBaseUnit, toDisplayUnit } from '@tokensoft/conversions'
const ethValue = '1'
const weiValue = '1000000000000000000'
const decimals = 18
const baseValue = toBaseUnit(ethValue, decimals) // => '1000000000000000000'
const displayValue = toDisplayUnit(weiValue, decimals) // => '1'
Functions
- toBaseUnit(value, decimals) ⇒
String
Converts value denominated in human-readable "display" unit (ether, bitcoins) to value denominated in on-chain "base" unit (wei, satoshis)
- toDisplayUnit(value, decimals) ⇒
String
Converts value denominated in on-chain "base" unit (wei, satoshis) to value denominated in human-readable "display" unit (ether, bitcoins)
String
toBaseUnit(value, decimals) ⇒ Converts value denominated in human-readable "display" unit (ether, bitcoins) to value denominated in on-chain "base" unit (wei, satoshis)
Kind: global function
Param | Type |
---|---|
value | String | Number | BigNumber |
decimals | String | Number | BigNumber |
String
toDisplayUnit(value, decimals) ⇒ Converts value denominated in on-chain "base" unit (wei, satoshis) to value denominated in human-readable "display" unit (ether, bitcoins)
Kind: global function
Param | Type |
---|---|
value | String | Number | BigNumber |
decimals | String | Number | BigNumber |