MCPcopy Index your code
hub / github.com/PaulRBerg/evm-bn

github.com/PaulRBerg/evm-bn @v1.2.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.2.0 ↗ · + Follow
2 symbols 12 edges 5 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Evm Bn GitHub Actions Coverage Styled with Prettier License: MIT

Evm Bn is a utility for converting between stringified fixed-point numbers and Ethers.js BigNumbers, as well as the reverse process. It is particularly useful for projects based on the Ethereum Virtual Machine (EVM), given that 1 ETH is equivalent to 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

$ pnpm add 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

Clone the repositories and install the dependencies:

$ pnpm install

Now you can start making changes.

License

This project is licensed under MIT.

Core symbols most depended-on inside this repo

toBn
called by 10
src/toBn.ts
fromBn
called by 4
src/fromBn.ts

Shape

Function 2

Languages

TypeScript100%

Modules by API surface

src/toBn.ts1 symbols
src/fromBn.ts1 symbols

For agents

$ claude mcp add evm-bn \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page