Big Number Problem

autotask to send out payments to people but I get this error when setting the value to more than 1e21. any value less than this works though.

Hey @vitaiUMICH! This is an error thrown by ethers.js. Whenever you try to use a very large numeric value, which may not be accurately represented by javascript's Number type, it throws an exception. The easiest way around this is to pass in the number as a string, so use "1000000000000000000000" (between quotes!) instead of 1e21, or use ethers BigNumber type instead.

thanks for the response.
My problem was that I had to multiply a decimal value by 1e18. For anyone else dealing with this problem, try doing something like this: (Math.floor(value)).toString() + '0'.repeat(18), where value can be numbers like (1000, 1.092321, etc..)

If you need to do any kind of arithmetic, I'd suggest going with the BigNumber class instead of directly manipulating strings. Alternatively, if it's just padding zeros to convert from eth to wei (ie multiplying by 1e18), you can use the formatUnits functions from ethers.

1 Like