Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ethersproject/units

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ethersproject/units

Unit conversion functions for Ethereum.

  • 5.0.0-beta.125
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is @ethersproject/units?

@ethersproject/units is a utility library for handling and converting between different units of Ether and other cryptocurrencies. It provides functions to parse and format units, making it easier to work with values in different denominations.

What are @ethersproject/units's main functionalities?

parseUnits

The `parseUnits` function converts a string representation of a value in a specified unit to its equivalent in wei (the smallest unit of Ether). In this example, '1.0' Ether is converted to '1000000000000000000' wei.

const { parseUnits } = require('@ethersproject/units');
const weiValue = parseUnits('1.0', 'ether');
console.log(weiValue.toString()); // '1000000000000000000'

formatUnits

The `formatUnits` function converts a value in wei to a string representation in a specified unit. In this example, '1000000000000000000' wei is converted to '1.0' Ether.

const { formatUnits } = require('@ethersproject/units');
const etherValue = formatUnits('1000000000000000000', 'ether');
console.log(etherValue); // '1.0'

commify

The `commify` function adds commas to a numeric string for better readability. In this example, '1234567.890123' is formatted to '1,234,567.890123'.

const { commify } = require('@ethersproject/units');
const formattedValue = commify('1234567.890123');
console.log(formattedValue); // '1,234,567.890123'

Other packages similar to @ethersproject/units

Keywords

FAQs

Package last updated on 03 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc