1

I have 2 contracts

  1. The first one cretes a token contract
  2. The second creates pre-sale contract

Pre-sale contract created with 0.5 eth for paying for gas

When trying to send 0.5 ethereum to pre-sale contract - received error: Canceled - Warning! Error encountered during contract execution [execution reverted]

Anybody can help me with this error?

Thx, attached both contracts below:

Token contract

pragma solidity ^0.4.24;

// ----------------------------------------------------------------------------
// ERC Token Standard #20 Interface
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md
// ----------------------------------------------------------------------------
contract ERC20Interface {
    function totalSupply() public constant returns (uint);
    function balanceOf(address tokenOwner) public constant returns (uint balance);
    function allowance(address tokenOwner, address spender) public constant returns (uint remaining);
    function transfer(address to, uint tokens) public returns (bool success);
    function approve(address spender, uint tokens) public returns (bool success);
    function transferFrom(address from, address to, uint tokens) public returns (bool success);

    event Transfer(address indexed from, address indexed to, uint tokens);
    event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
}


// ----------------------------------------------------------------------------
// Contract function to receive approval and execute function in one call
//
// Borrowed from MiniMeToken
// ----------------------------------------------------------------------------
contract ApproveAndCallFallBack {
    function receiveApproval(address from, uint256 tokens, address token, bytes data) public;
}


// ----------------------------------------------------------------------------
// Owned contract
// ----------------------------------------------------------------------------
contract Owned {
    address public owner;
    address public newOwner;

    event OwnershipTransferred(address indexed _from, address indexed _to);

    constructor() public {
        owner = msg.sender;
    }

    modifier onlyOwner {
        require(msg.sender == owner);
        _;
    }

    function transferOwnership(address _newOwner) public onlyOwner {
        newOwner = _newOwner;
    }

    function acceptOwnership() public {
        require(msg.sender == newOwner);
        emit OwnershipTransferred(owner, newOwner);
        owner = newOwner;
        newOwner = address(0);
    }
}


// ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and a
// fixed supply
// ----------------------------------------------------------------------------
contract VOBLA10 is ERC20Interface, Owned {
    using SafeMath for uint;

    string public symbol;
    string public  name;
    uint _totalSupply;
    uint8 public decimals;

    mapping(address => uint) balances;
    mapping(address => mapping(address => uint)) allowed;


    // ------------------------------------------------------------------------
    // Constructor
    // ------------------------------------------------------------------------
    constructor() public {
        symbol = "VLAB";
        name = "VOBLA10";
        decimals = 18;
        _totalSupply = 300000000 * (10**uint(decimals));
        balances[owner] = _totalSupply;
        emit Transfer(address(0), owner, _totalSupply);
    }


    // ------------------------------------------------------------------------
    // Total supply
    // ------------------------------------------------------------------------
    function totalSupply() public view returns (uint) {
        return _totalSupply.sub(balances[address(0)]);
    }


    // ------------------------------------------------------------------------
    // Get the token balance for account `tokenOwner`
    // ------------------------------------------------------------------------
    function balanceOf(address tokenOwner) public view returns (uint balance) {
        return balances[tokenOwner];
    }


    // ------------------------------------------------------------------------
    // Transfer the balance from token owner's account to `to` account
    // - Owner's account must have sufficient balance to transfer
    // - 0 value transfers are allowed
    // ------------------------------------------------------------------------
    function transfer(address to, uint tokens) public returns (bool success) {
        balances[msg.sender] = balances[msg.sender].sub(tokens);
        balances[to] = balances[to].add(tokens);
        emit Transfer(msg.sender, to, tokens);
        return true;
    }


    // ------------------------------------------------------------------------
    // Token owner can approve for `spender` to transferFrom(...) `tokens`
    // from the token owner's account
    //
    // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
    // recommends that there are no checks for the approval double-spend attack
    // as this should be implemented in user interfaces
    // ------------------------------------------------------------------------
    function approve(address spender, uint tokens) public returns (bool success) {
        allowed[msg.sender][spender] = tokens;
        emit Approval(msg.sender, spender, tokens);
        return true;
    }


    // ------------------------------------------------------------------------
    // Transfer `tokens` from the `from` account to the `to` account
    //
    // The calling account must already have sufficient tokens approve(...)-d
    // for spending from the `from` account and
    // - From account must have sufficient balance to transfer
    // - Spender must have sufficient allowance to transfer
    // - 0 value transfers are allowed
    // ------------------------------------------------------------------------
    function transferFrom(address from, address to, uint tokens) public returns (bool success) {
        balances[from] = balances[from].sub(tokens);
        allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
        balances[to] = balances[to].add(tokens);
        emit Transfer(from, to, tokens);
        return true;
    }


    // ------------------------------------------------------------------------
    // Returns the amount of tokens approved by the owner that can be
    // transferred to the spender's account
    // ------------------------------------------------------------------------
    function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
        return allowed[tokenOwner][spender];
    }


    // ------------------------------------------------------------------------
    // Token owner can approve for `spender` to transferFrom(...) `tokens`
    // from the token owner's account. The `spender` contract function
    // `receiveApproval(...)` is then executed
    // ------------------------------------------------------------------------
    function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
        allowed[msg.sender][spender] = tokens;
        emit Approval(msg.sender, spender, tokens);
        ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
        return true;
    }

    // ------------------------------------------------------------------------
    // Owner can transfer out any accidentally sent ERC20 tokens
    // ------------------------------------------------------------------------
    function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
        return ERC20Interface(tokenAddress).transfer(owner, tokens);
    }
}

Pre-sale contract

pragma solidity >=0.4.24 <0.6.0;

interface token {
    function transfer(address receiver, uint amount) external;
}

contract VoblaCrowdsaleTemp11 is ReentrancyGuard {

    using SafeMath for uint256;

    address private _wallet; // wallet of token owner
    uint256 private fundingGoal; // in ether -> 10K
    uint256 private amountRaised;
    uint256 private price;
    token private tokenReward;  // address of Vobla # should be token?

    uint256 private deadline;
    uint256 private minimum;

    bool crowdsaleClosed = false;

    /**
     * Constructor
     *
     * Setup the owner
     */
    constructor(
        address ifSuccessfulSendTo, // wallet of token owner
        uint fundingGoalInEthers, // 10K ether -> 10K * 170 tokens
        uint etherCostOfEachToken, // 170
        uint256 durationInMinutes,  // should check if solidity understands hours or days constant
        address addressOfTokenUsedAsReward // address of Vobla
    ) public payable {
        require(etherCostOfEachToken > 0);
        require(durationInMinutes > 0);
        require(ifSuccessfulSendTo != address(0));
        require(address(addressOfTokenUsedAsReward) != address(0));

        amountRaised = 0; // initial amount - in wei
        _wallet = ifSuccessfulSendTo; // wallet of token owner
        fundingGoal = fundingGoalInEthers*10**18; // 10K ether -> 10K * 170 tokens -> in wei
        price = etherCostOfEachToken*10**18; // price in wei per 1 ether
        tokenReward = token(addressOfTokenUsedAsReward); // address of Vobla
        deadline = now + durationInMinutes * 1 minutes;
    }

    /**
     * Fallback function
     *
     * The function without name is the default function that is called whenever anyone sends funds to a contract
     */
    function () public payable {
        require(!crowdsaleClosed);
        crowdsaleClosed = _isDeadlineReached(deadline);
        require(!crowdsaleClosed);
        require(msg.sender != address(0));

        uint256 amount = msg.value; // in wei
        require(amount > 0);

        crowdsaleClosed = _isGoalReached(amount);

        uint256 tokens = amount.mul(price);

        amountRaised = amountRaised.add(amount);

        tokenReward.transfer(msg.sender, tokens);

        _wallet.transfer(amount);
    }

    function _isGoalReached(uint256 weiAmount) internal view returns(bool) {
        return (amountRaised.add(weiAmount) >= fundingGoal);
    }

    function _isDeadlineReached(uint256 time) internal view returns(bool) {
        return (now >= time);
    }
}
  • Really difficult to say without a lot more details. What I'd recommend is to etiher try to debug the contract or comment out the require statements one by one until you find out which reverts the contract. – Lauri Peltonen Apr 7 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.