[Ethereum] Meaning of ‘using SafeMath for uint256;’


Hi I just started to study solidity. Can you tell me what is using SafeMath for uint256;?


Best Answer

SafeMath is a solidity math library especially designed to support safe math operations: safe means that it prevents overflow when working with uint. You can find it in zeppelin-solidity SafeMath.

From the official documentation:

The directive using A for B; can be used to attach library functions (from the library A) to any type (B). These functions will receive the object they are called on as their first parameter (like the self variable in Python).

The effect of using A for *; is that the functions from the library A are attached to any type.

Hope it helps~

Related Topic