I'm working on an auction feature in my DApp and having problems correctly adding together two
The contract stores two important values:
minBidIncrement variable - which I've set to
0.1 ETH, and
highestBidAmount variable - which stores the highest bid anyone has made to date.
Thus, if the last highest bid was say
2.5 ETH, I want to make sure the next allowable bid would be at least that plus the
minBidIncrement, meaning it should be:
2.5 ETH + 0.1 ETH which equals
Its pretty straight forward stuff.
So I'm doing this:
let minNextBid = highestBidAmount + minBidIncrement;
but what I get from that is some crazy huge value which causes my Dapp to freak out and Metamask to give me errors.
Here's what's happening underneath the hood:
highestBidAmount comes back as
minBidIncrement also comes back as
(both of those are fine cause they're 18 decimal places, which means they're really
So next when I set my
minNextBid, I'm basically doing
100000000000000000, but that yields:
And when I then convert that to ETH, I get this value:
which isn't at all what I was expecting to get. What I was expecting to get was
0.2 ETH, but I get that astronomical value instead.
So what's happening here? What am I doing wrong? What's the right way to do this?