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

evm-bn

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

evm-bn

Convert fixed-point numbers to ethers big numbers and vice-versa

  • 1.1.1
  • npm
  • Socket score

Version published
Weekly downloads
1.3K
increased by2.28%
Maintainers
1
Weekly downloads
 
Created
Source

Evm Bn Coverage Status Styled with Prettier Commitizen Friendly license: Unlicense

Convert fixed-point numbers to ethers big numbers and vice-versa. This is useful for EVM-related projects, since 1 ETH is 1e18 wei.

  • Accepts scientific notation.
  • Limits the precision to 78 digits.
  • Enforces 60 integer digits and 18 fractional digits.
  • Designed to be used alongside @ethersproject/bignumber.
  • Slices the fractional digits automatically at position n + 1 and above, with n the number of decimals, rounding down in the process.

Install

With yarn:

$ yarn add evm-bn

Or npm:

$ npm install evm-bn

Usage

To Bn

import type { BigNumber } from "@ethersproject/bignumber";
import { toBn } from "evm-bn";

// 3141500000000000000
const foo: BigNumber = toBn("3.1415");

// 115792089237316195423570985008687907853269984665640564039457584007913129639935
const bar: BigNumber = toBn("115792089237316195423570985008687907853269984665640564039457.584007913129639935");

// 100000000000000
const baz: BigNumber = toBn("100e6", 6);

From Bn

import type { BigNumber } from "@ethersproject/bignumber";
import { fromBn } from "evm-bn";

// 3.1415
const foo: BigNumber = fromBn(BigNumber.from("3141500000000000000"));

// 115792089237316195423570985008687907853269984665640564039457.584007913129639935
const bar: BigNumber = fromBn(
  BigNumber.from("115792089237316195423570985008687907853269984665640564039457584007913129639935"),
);

// 100000000
const baz: BigNumber = fromBn(BigNumber.from("100000000000000"), 6);

Contributing

Feel free to dive in! Open an issue, start a discussion or submit a PR.

Set Up

Install the dependencies:

$ yarn install

License

Unlicense © Paul Razvan Berg

Keywords

FAQs

Package last updated on 27 Oct 2021

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