Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@ethersproject/units
Advanced tools
@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.
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'
The `web3-utils` package is part of the Web3.js library and provides utility functions for Ethereum dapp development. It includes functions for unit conversion, such as `toWei` and `fromWei`, which are similar to `parseUnits` and `formatUnits` in @ethersproject/units. However, `web3-utils` is more tightly integrated with the Web3.js ecosystem.
The `bignumber.js` package is a library for arbitrary-precision decimal and non-decimal arithmetic. While it does not specifically focus on Ethereum unit conversions, it can be used in conjunction with other libraries to handle large numbers and perform precise calculations, similar to the functionality provided by @ethersproject/units.
The `ethers` package is a complete Ethereum library that includes the `@ethersproject/units` module as part of its functionality. It provides a comprehensive set of tools for interacting with the Ethereum blockchain, including unit conversion, contract interaction, and wallet management. It is more feature-rich compared to @ethersproject/units alone.
This sub-module is part of the ethers project.
It contains functions to convert between string representations and numeric representations of numbers, including those out of the range of JavaScript.
For more information, see the documentation.
Most users will prefer to use the umbrella package, but for those with more specific needs, individual components can be imported.
const {
formatUnits,
parseUnits,
formatEther,
parseEther,
commify
} = require("@ethersproject/units");
MIT License
FAQs
Unit conversion functions for Ethereum.
The npm package @ethersproject/units receives a total of 587,609 weekly downloads. As such, @ethersproject/units popularity was classified as popular.
We found that @ethersproject/units demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.