Hey guys, good day and sorry to bother but I ran into a problem I need help so I am interacting with a smart contract using ether with react and to approve a token before sale, I need to pass allowance as an argument to the approve function, which is a very big number and from my research I found that javaScript can take only or handle 2^53 (not entirely sure) numbers, whereas mine is allowance = String(BigInt("2") ** BigInt("256") - BigInt("1")) and so I get the error
" Cannot convert a BigInt value to a number"
any help or work around would be really appreciated
Jun 11, 2022, 8:09 PM
Did you mean to say ethers instead of ether? If so, ethers comes with its own bigint lib to avoid such problems
Jun 11, 2022, 8:26 PM
so you want to pass in 2^255 as allowance? That seems awfully high. If you use any f the libraries you should be fine but as you did it, you cant use numeric arthimatic in js directly.
if you use BigNumber for instance
then you can do something like new BigNumber(1).exponititaedBy(255);
Misspelled, but you get the drift:
https://github.com/MikeMcl/bignumber.js/
Ethers.js also has some similar functions
Jun 11, 2022, 9:02 PM
What about ethers.utils.parseUnits ?
Jun 11, 2022, 9:02 PM
He wants to do arithamtic, so no, wouldn't work. It will go outside the bounds of the number type in JS.
Jun 11, 2022, 9:05 PM
ethers does all this and more.
Jun 11, 2022, 9:05 PM
Btw, with BigInt: the functioncall is pow.
So BigInt(1).pow(255);
Jun 11, 2022, 9:05 PM
divide by 1e18 i think works if it’s incoming
Jun 11, 2022, 9:06 PM
https://testnet.binance.org/faucet-smart
- when it works...that is.
Jun 11, 2022, 9:08 PM
its working
do it everyday
Jun 11, 2022, 9:08 PM
Yea I later saw it
Thanks a ton
I solved it
Thanks a ton
I solved it
Yea man
Thanks a lot I found a way to resolve it l. Grateful
Thanks a lot I found a way to resolve it l. Grateful
Noticed it.
I am just used to working with (**) operator when ever I am working with react or next.js
I am just used to working with (**) operator when ever I am working with react or next.js
Jun 12, 2022, 2:37 AM