JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 74
  • Score
    100M100P100Q65521F
  • License ISC

Kitchensink of ethereum utils

Package Exports

  • eth-helpers

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (eth-helpers) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

eth-utils

Kitchensink of ethereum utils

Usage

Units

const units = require('eth-utils/units')
const { Wei, Ether, GWei } = units

const gasPrice = 16n * GWei
const value = units.parse('2.7811', { from: Ether }) // implicit `to: Wei`

const tx = // Send tx

console.log(units.format(address.balance, { to: Ether, from: Wei, decimals: 4 }))

API

Utils

const str = utils.format(nullish|string|Buffer|number|BigInt)

Format any of the above types as a eth hex string.

const receipt = async utils.mined(txHash, eth)

Wait for a transaction to be mined

Units

The units module contains a list of constants as well as helper functions to convert to and from strings and do lossless conversion.

Unit constants include as BigInt:

  • Wei
  • KWei / babbage
  • MWei / lovelace
  • GWei / shannon
  • µEther / microether / szabo
  • mEther / milliether / finney
  • Ether
  • KEther
  • MEther
  • GEther
  • TEther

const bigint = units.convert(value, from, [to = Wei])

Lossless unit conversion to BigInt. Asserts that no precision is lost.

const number = units.convertLossy(value, from, [to = Wei])

Lossy unit conversion to Number. Not suitable to exact calculations.

const str = units.format(value, { from = Wei, to = Wei, decimals = null })

Format BigInt as a string with from basis to to basis. Optional set the number of decimals similar to toFixed

const bigint = units.parse(string, { from, to = Wei })

Parse a string number into BigInt with specified basis.

Install

npm install eth-utils

License

ISC