0

I'm trying to parse some ETH amounts to display them on client side, using ethers v6.11.1 but I get this error. The same code used to work fine with ethers v5, I have checked the type of value, and it is string.

const parseAmount = (value: string): number => {
  return ethers.toNumber(value) * 10 ** -18;
};

Error:

TypeError: overflow (argument="value", value=21150000000000000, code=INVALID_ARGUMENT, version=6.11.1)

1 Answer 1

1

Fixed by using the method formatEther.

const parseAmount = (value: string): number => {
  return Number(ethers.formatEther(value));
};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.