August 2018
Intermediate to advanced
404 pages
11h 19m
English
There are best practices and reusable code that can be used to avoid such bugs in your smart contract. One perfect example is the SafeMath library of openzeppelin. This library introduces a few functions that can be used instead of the regular arithmetic operators. These functions include conditions to ensure that no overflow or underflow can happen:
pragma solidity ^0.4.24;library SafeMath { /** * @dev Function to add two numbers */ function add(uint256 a, uint256 b) internal pure returns (uint256 c) { c = a + b; assert(c >= a); return c; } function sub(...) { ... } function mul(...) { ... } function div(...) { ... }}
To use this library, import SafeMath from the openzeppelin GitHub repository at https://github.com/OpenZeppelin/openzeppelin-solidity ...
Read now
Unlock full access