You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, this is not necessary, because "0" is the implicit default value for uint8. You might be able to save a little bit of gas if you refactor the code like this:
- function tokenDecimals(address token) public view returns (uint8) {+ function tokenDecimals(address token) public view returns (uint8 decimals) {
(bool success, bytes memory data) = token.staticcall(abi.encodeWithSelector(IERC20Metadata.decimals.selector));
- return success && data.length == 32 ? abi.decode(data, (uint8)) : 0;+ if (success && data.length == 32) {+ decimals = abi.decode(data, (uint8));+ }
Activity
PaulRBerg commentedon May 24, 2023
Though, on second thoughts, I am not so sure that this would save gas.