'bignumber.js@^9.0.1, which was used for Dapp over AWS S3, causes an invalid Big number error. Please teach me how to solve this issue
Recently, I deployed Dapp on Aws S3 bucket. I used bignumber.js@^9.0.1 to compute the liquidity pool price properly and also to prevent the overflow. I used React to build this app, and thus I assume all the packages and relative libraries should be uploaded through packages.json. While it bignumber.js library worked well in localhost, it causes the invalid bignumber value error on Aws S3. Here is the error message I received from the server:
"""
error event: Error: invalid BigNumber value (argument="value", value="1000000000000000000", code=INVALID_ARGUMENT, version=bignumber/5.0.14)
at e.value (index.ts:205)
at e.value (index.ts:217)
at e.value (index.ts:221)
at Function.value (bignumber.ts:281)
at r.value (number.ts:21)
at array.ts:71
at Array.forEach (<anonymous>)
at q (array.ts:54)
at r.value (tuple.ts:23)
at e.value (abi-coder.ts:106)
"""
I assumed that it might happen if the bignumber.js version is deprecated to 5.0.14. Is it possible that a deprecated library dependency version installed while I used the upper version and recorded it in package.json? Please provide any advice on how to solve this issue. I have been struggling with this for days...
Here is the list of dependencies I used:
"dependencies": {
"@aws-cdk/aws-s3": "^1.9.0",
"@material-ui/core": "^4.11.2",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"axios": "^0.21.1",
"bignumber.js": "^9.0.1",
"electron": "^11.2.0",
"googleapis": "39",
"material-ui": "^0.20.2",
"nw-react-slider": "^2.0.1",
"react": "^17.0.1",
"react-bootstrap": "^1.4.3",
"react-copy-to-clipboard": "^5.0.2",
"react-dom": "^17.0.1",
"react-google-charts": "^3.0.15",
"react-icons": "^4.1.0",
"react-minimal-pie-chart": "^8.1.0",
"react-motion": "^0.5.2",
"react-notifications": "^1.7.2",
"react-router-dom": "^5.2.0",
"react-script": "^2.0.5",
"react-scripts": "4.0.1",
"react-slider": "^1.1.2",
"reactstrap": "^8.8.1",
"styled-components": "^5.2.1",
"tabletop": "^1.6.3",
"web-vitals": "^0.2.4",
"web3": "^1.3.1"
},
Solution 1:[1]
Meet the same issue after deployed Dapp to production environment.
Execution Failed details: invalid BigNumber value (argument="value", value="0", code=INVALID_ARGUMENT, version=bignumber/5.2.0)
The BigNumber in above error message comes from @ethersproject/bignumber.
You can check why the package is installed,
yarn why @ethersproject/bignumber
My Dapp is using web3,
- Hoisted from "web3#web3-eth#web3-eth-abi#@ethersproject#abi#@ethersproject#hash#@ethersproject#abstract-signer#@ethersproject#abstract-provider#@ethersproject#bignumber"
Resolve this issue by correcting the parameters before AbiCoder - encode in my case,
from
await myContract.methods.poolInfo(new BigNumber(pid)).call()
to
await myContract.methods.poolInfo(pid).call()
Solution 2:[2]
I am the author of bignumber.js and it doesn't include a bignumber.ts file or produce an error message which states "invalid BigNumber value".
I assumed that it might happen if the bignumber.js version is deprecated to 5.0.14.
There isn't a bignumber.js version 5.0.14.
Solution 3:[3]
This worked for me, Use toBN instead of bignumber
const DIVIDER = Math.pow(10, 18);
const BN = web3.utils.toBN;
const amount = new BN(1000).mul(new BN(DIVIDER));
Solution 4:[4]
This is big number issue for frontend when I connect to metamask. Please try such as the below. I have fixed it in this way easily.
<pre>
import { BigNumber} from 'ethers';
....
const decimals = 18;
const trans_amount = 1500;
const amount= BigNumber.from(trans_amount).mul(BigNumber.from(10).pow(decimals));
consoel.og("amount is ", amount);
</pre>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | linxux |
| Solution 2 | MikeM |
| Solution 3 | BehnamHesami |
| Solution 4 |
