@tokensoft/conversions

Utils to convert values between on-chain "base" and human-readable "display" units

Usage no npm install needed!

<script type="module">
  import tokensoftConversions from 'https://cdn.skypack.dev/@tokensoft/conversions';
</script>

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)

toBaseUnit(value, decimals) ⇒ String

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

toDisplayUnit(value, decimals) ⇒ String

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