Smart Contracts: Don’t Reinvent the Wheel


SafeMath is a library that ensures safe arithmetic operations by reverting the transaction if the bounds of an integer data type are exceeded.

SafeMath example.

The using statement indicates to the compiler that the contract is using functions defined in SafeMath for uint operations. Instead of using arithmetic operators (+, -, *, /, %), use the functions add(), sub(), mul(), div(), and mod().