Is there a tool to check if all of my smart contract code is compatible pragma version? My contract returns different results in some nodes and I thought maybe they use different versions of Solidity.
1 Answer
This is the job of the compiler. If you're attempting to use a feature that is not available in the version encapsulated by your pragma, you will get an error.
For example:
pragma solidity ^0.7.0;
contract ErrorExample {
function foo(uint256 a, uint256 b) external view returns (uint256) {
unchecked {
return a + b;
}
}
}
Throws with the following error:
ParserError: Expected primary expression.
This is because unchecked arithmetic has been added in version 0.8; it wasn't available in Solidity v0.7 and below.
-
Thanks Paul. Does Remix compiler checks for this errors too? What if there's a overflow in arithmetic? I get different return values from different nodes for a same function. Please check this question too ethereum.stackexchange.com/questions/103527/…– M MCommented Jul 17, 2021 at 19:33
-
Arithmetic underflow and overflow used to not be checked for in Solidity. Only since v0.8 the compiler started reverting when an addition, subtraction, division or multiplications operations goes outside the permitted bounds. Commented Jul 18, 2021 at 10:08
-
Thanks Paul. I checked it again and it was a Arithmetic overflow.– M MCommented Jul 18, 2021 at 14:56