0

I'm trying to to subctract in type script big numbers, but getting error...

const supply1 = 100000;
 const _amount = 100;
 const supply = ethers.utils.parseEther(`${supply1}`);
 const diff = supply - _amount;

enter image description here

1 Answer 1

2

The ethers.utils.parseEther function returns a BigNumber.

To make arithmetic operations on it you must explicitely call the operation implementation, in your case that would be the .sub method which expects a BigNumberish parameter.

So you'd want to change :

const diff = supply - _amount;

to :

const diff = supply.sub(_amount);

Just keep in mind that diff will be of type BigNumber, if you need to convert it to another type such as number or string, you can refer to the appropriate part of the documentation.

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.