All Projects → paulrberg → evm-bn

paulrberg / evm-bn

Licence: Unlicense license
Convert fixed-point numbers to ethers big numbers and vice-versa.

Programming Languages

typescript
32286 projects
shell
77523 projects

Projects that are alternatives of or similar to evm-bn

blockhead
Crypto portfolio tracker, DeFi dashboard, NFT viewer and data explorer for the Ethereum/EVM-based blockchain ecosystem and the web 3.0-powered metaverse https://gitcoin.co/grants/2966/blockhead
Stars: ✭ 41 (+24.24%)
Mutual labels:  evm, ethersjs
solidity-create2-example
Example of how to use the CREATE2 opcode released in the Constantinople update for Ethereum
Stars: ✭ 97 (+193.94%)
Mutual labels:  evm
prb-math
Solidity library for advanced fixed-point math
Stars: ✭ 404 (+1124.24%)
Mutual labels:  evm
intx
intx – extended precision integer library
Stars: ✭ 83 (+151.52%)
Mutual labels:  evm
pyevmasm
Ethereum Virtual Machine (EVM) disassembler and assembler
Stars: ✭ 206 (+524.24%)
Mutual labels:  evm
emerald-web3-gateway
The Web3 Gateway for the Oasis Emerald ParaTime.
Stars: ✭ 19 (-42.42%)
Mutual labels:  evm
hebimath
arbitrary precision arithmetic library
Stars: ✭ 37 (+12.12%)
Mutual labels:  bignumber
BigInteger
Be limited not by the size of your register but by the bulk of your RAM.
Stars: ✭ 13 (-60.61%)
Mutual labels:  bignumber
ohmfork-autoclaim
automatically claim and restake vested bonds (mints) from SnowbankDAO, KlimaDAO, Wonderland, and other OlympusDAO forks
Stars: ✭ 40 (+21.21%)
Mutual labels:  evm
send-tx
🤝 Sign & send Ethereum transactions
Stars: ✭ 14 (-57.58%)
Mutual labels:  ethersjs
ZYX-20
A Zyx Network client based on the go-ethereum fork
Stars: ✭ 0 (-100%)
Mutual labels:  evm
ethereum-evm-illustrated
Ethereum EVM illustrated
Stars: ✭ 170 (+415.15%)
Mutual labels:  evm
staking
A dAPP for minting, burning, and earning on the Synthetix Protocol.
Stars: ✭ 66 (+100%)
Mutual labels:  ethersjs
vandal
Static program analysis framework for Ethereum smart contract bytecode.
Stars: ✭ 121 (+266.67%)
Mutual labels:  evm
exchain
⛓️ The Infrastructure of Decentralized Exchange ✨
Stars: ✭ 349 (+957.58%)
Mutual labels:  evm
revm
Revolutionary Machine (revm) is a fast Ethereum virtual machine written in rust.
Stars: ✭ 383 (+1060.61%)
Mutual labels:  evm
democracy
Tools for peer-to-peer privacy with Ethereum and AZTEC
Stars: ✭ 36 (+9.09%)
Mutual labels:  evm
c4-common-issues
A collection of common security issues and possible gas optimizations in solidity smart contracts
Stars: ✭ 85 (+157.58%)
Mutual labels:  evm
go-ubiq
Ubiq fork of Geth
Stars: ✭ 82 (+148.48%)
Mutual labels:  evm
sdk-go
Tools to work with the Injective Chain, Injective EVM and EIP712.
Stars: ✭ 29 (-12.12%)
Mutual labels:  evm

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].