Is it possible to preserve a currency designation after performing calculations? For example, using Remix, in variable declaration I have something like this:

uint256 myConstant = 100 gwei;
uint256 newNum;

Once the constructor executes, a calculation is performed, e.g.:

newNum = myConstant + 10;

In a subsequent function, the user is required to submit the correct amount in the Remix Value field; the code includes a conditional msg.value != newNum, then throw an error. Thus, in this case, when I specify 110 gwei in the Value field, the error is thrown. My guess is that once I perform some math on the original myConstant variable in gwei, that those units are lost? I've tried adding the keyword gwei to the variable declaration for newNum and the formula line; neither option is allowed.

1 Answer 1


gwei, ether, days, hours etc. All these keywords make the code more readable and easy to understand. In your case myConstant still holds the value 100000000000 so when you add 10 it becomes 100000000010 but not 110000000000(110 Gwei)

  • Yep, that was it. I had to use the wei conversion instead. Thanks.
    – Mat
    Commented Oct 7, 2023 at 0:20

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.