question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BigNumber error on small value

See original GitHub issue

ethers.utils.parseEther('0.0007000000000000001') throws Error: underflow occurred (operation=“division”, fault=“underflow”, version=4.0.39) How can I fix it?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

8reactions
paulrbergcommented, Dec 12, 2021

For what it’s worth, I ended up building my own solution for this problem.

It’s a tiny npm package called evm-bn, which works like this;

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

const foo: BigNumber = toBn("3.1415");
const bar: BigNumber = toBn("115792089237316195423570985008687907853269984665640564039457.584007913129639935");
const baz: BigNumber = toBn("100e6", 6);
4reactions
SCBuergelcommented, Dec 12, 2021

Since this still comes up when searching, here my solution: Do not do .mul with a number < 1, instead do .div with a number > 1

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to call contract function from web3 with big number as ...
I am trying to call a custom function of a contract that expects a parameter of unit256. I'm calling this function from web3...
Read more >
Ethers JS BigNumber Errors - Ethereum Stack Exchange
Ethers JS BigNumber Errors ... I read that this should be done using BigNumber , using the following ... can you try it...
Read more >
bignumber.js API - GitHub Pages
If value is a BigNumber instance and BigNumber.DEBUG is true , then this method will also check if value is well-formed, and throw...
Read more >
How to fix EthersJS "underflow" error | BigNumber.from Error
I got this EthersJS underflow error that referenced the function BigNumber.from, and was confused because I never called BigNumber.from.
Read more >
BigNumber - ethers
Most operations which need to return a value will return a BigNumber and ... easy to make mistakes, which is not possible on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found