# Practicing Safemath for Smart Contracts with Solidity and Openzeppelin

May 18, 2018 · 4 min read

`pragma solidity ^0.4.22;contract Lucas {uint[] lucseries;  // n = how many in the series to return  function generateLuc(uint n) public {    // set 1st and 2nd entries    lucseries.push(2);    lucseries.push(1);    // generate subsequent entries    for (uint i=2; i < n ; i++) {      lucseries.push(lucseries[i-1] + lucseries[i-2]);    }   }}`
`pragma solidity ^0.4.22;import "github.com/OpenZeppelin/zeppelin-solidity/contracts/math/SafeMath.sol";contract Lucas {      using SafeMath for uint; //    uint[] lucseries;   // n = how many in the series to return   function generateLuc(uint n) public {    // set 1st and 2nd entries    lucseries.push(2);    lucseries.push(1);    // generate subsequent entries    for (uint i=2; i < n ; i++) {      lucseries.push(lucseries[i-1].add( lucseries[i-2]));    }   }}`
`pragma solidity ^0.4.22;import "github.com/OpenZeppelin/zeppelin-solidity/contracts/math/SafeMath.sol";contract Exception {      using SafeMath for uint; //    uint two_to_the_256_power_minus_one = 115792089237316195423570985008687907853269984665640564039457584007913129639935; //2 to the 256 power minus 1   uint more = two_to_the_256_power_minus_one + two_to_the_256_power_minus_one;    }`

## Coinmonks

### By Coinmonks

A newsletter that brings you week's best crypto and blockchain stories and trending news directly in your inbox, by CoinCodeCap.com Take a look

Written by

Written by