Can one of you awesome people look over this contract for any issues? Its meant to be a simple crowdsale contract that has a deadline, a goal, and a minimum.

Participants should have the option of withdrawing their funds after the deadline, if the goal was not met.

pragma solidity ^0.4.2;

 * @title SafeMath
 * @dev Math operations with safety checks that throw on error
library SafeMath {
  function mul(uint256 a, uint256 b) internal constant returns (uint256) {
    uint256 c = a * b;
    assert(a == 0 || c / a == b);
    return c;

  function div(uint256 a, uint256 b) internal constant returns (uint256) {
    // assert(b > 0); // Solidity automatically throws when dividing by 0
    uint256 c = a / b;
    // assert(a == b * c + a % b); // There is no case in which this doesn't hold
    return c;

  function sub(uint256 a, uint256 b) internal constant returns (uint256) {
    assert(b <= a);
    return a - b;

  function add(uint256 a, uint256 b) internal constant returns (uint256) {
    uint256 c = a + b;
    assert(c >= a);
    return c;

contract NextLevelCrowdsale {
    using SafeMath for uint256;

address public beneficiary;
uint public fundingGoal = 1200 ether;
uint public amountRaised;
uint public deadline = 1504180740;
uint public price;
bool fundingGoalReached = false;
bool crowdsaleClosed = false;

mapping(address => uint256) public balanceOf;

event GoalReached(address beneficiary, uint amountRaised);
event FundTransfer(address backer, uint amount, bool isContribution);

function NextLevelCrowdsale(
    uint fundingGoalInEthers,
    uint crowdsaleDeadline,
    uint minimumAmount) {
        fundingGoalInEthers = fundingGoal;
        minimumAmount = 1 ether;
        crowdsaleDeadline = deadline;

function () payable {
    if (crowdsaleClosed) revert();
    uint amount = msg.value;
    if (amount < 1 ether) revert();
    FundTransfer(msg.sender, amount, true);

modifier afterDeadline() { if (now >= deadline) _; }

//Checks if the goal or time has been reached and ends the campaign
function checkGoalReached() afterDeadline {
    if (amountRaised >= fundingGoal) {
        fundingGoalReached = true;
        GoalReached(beneficiary, amountRaised);
    crowdsaleClosed = true;

 function safeWithdrawal() afterDeadline {
    if (!fundingGoalReached) {
        uint amount = balanceOf[msg.sender];
        balanceOf[msg.sender] = 0;
        if (amount > 0) {
            if (msg.sender.send(amount)) {
                FundTransfer(msg.sender, amount, false);
            } else {
                balanceOf[msg.sender] = amount;

    if (fundingGoalReached && beneficiary == msg.sender) {
        if (beneficiary.send(amountRaised)) {
            FundTransfer(beneficiary, amountRaised, false);
        } else {
            //If we fail to send the funds to beneficiary, unlock funders balance
            fundingGoalReached = false;


closed as too broad by Thomas Jay Rush, lungj, eth Aug 10 '17 at 5:21

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


What I see from the first glance:

  1. The pragma should indicate the latest (or at least not as old) compiler version;
  2. transfer is the preferred way for sending ether.

Note that tools exist for static analysis of contracts.

  • Thanks for the link to Securify. I'll definitely be using that quite a bit. I did have an issue with using beneficiary.transfer(amountRaised) rather than send. The IDE throws the error: "tuple cannot be implicitly converted to type bool". Also, won't send be fine since the contract implements an else in the if statement? – Aigbe Idahosa Aug 10 '17 at 3:19

It's great seeing a fellow Nigerian on the ethereum/stack platform. I have done a quick look at the code and it's pretty much okay. However, I'll try to check it later on my PC. The logic is quite straightforward and everything is in order.

  • Thanks for giving it a look over! I'm still wondering about the use of send however. Just having some issues in implementing .transfer. – Aigbe Idahosa Aug 10 '17 at 3:23
  • Okay, I saw your post about . transfer not being able to execute correctly. Have you tried to convert it explicitly? Send me a mail via [williams234jack] - gmail. Note: I'll remove mail after seeing your mail – tRosJan Aug 10 '17 at 7:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.