0

I am trying to create a contract for crowdsale using OpenZeppelin lib. I have imported everything necessary to the contract and initialized everything properly, but when I am trying to deposit funds in the contract the transaction is unsuccessful.

I've traced the error back to the _forwordFunds() method, but now I am lost any help will be appreciated.

Following is my contract:

contract Crowdsale is RefundableCrowdsale, CappedCrowdsale, PostDeliveryCrowdsale, AllowanceCrowdsale, StagedCrowsale {
    constructor(
        uint256 rate, address wallet, IERC20 token,
        uint256 openingTime, uint256 closingTime,
        uint cap,
        uint256 goal,
        address tokenWallet) 
        Crowdsale(rate, wallet, token)
        TimedCrowdsale(openingTime, closingTime)
        CappedCrowdsale(cap)
        RefundableCrowdsale(goal)
        AllowanceCrowdsale(tokenWallet)
        StagedCrowsale()
    public {}

    //Error: buyTokens() --> _forwardFunds
    function() external payable {
        buyTokens(msg.sender); 
    }
}        

.

contract RefundableCrowdsale is FinalizableCrowdsale {
        ⋮ 
    RefundEscrow private _escrow;
        ⋮ 
    constructor(uint256 goal) public {
        require(goal > 0, "Goal should be greater than zero.");
        _escrow = new RefundEscrow(wallet());
        _goal = goal;
    }
        ⋮ 
    function _forwardFunds() internal {
        _escrow.deposit.value(msg.value)(msg.sender); //What is this?
    }
}

Edit1: So I have traced the error back to the deposit function, following line is throwing the error. _deposits[payee] = _deposits[payee]+(amount);

function deposit(address payee) public onlyPrimary payable {
  uint256 amount = msg.value;
  require(payee!=address(0),"Invalid address");
  require(amount > 0,"Invalid amount");
  _deposits[payee] = _deposits[payee]+(amount);//Error
  emit Deposited(payee, amount);
}

OpenZeppelin
RefundableCrowdsal
RefundEscrow

0

To answer your "what is this?" about line _escrow.deposit.value(msg.value)(msg.sender);: it is calling the function deposit of _escrow with Ether value msg.value. The function is payable so it can receive Ether. The last part just provides the required parameter.

Otherwise I'm not sure what causes your exception. If you can't debug it further with debug tools, you can just edit the OpenZeppelin contracts and comment out require statements until you find out which one causes the problem. It's slow but often the only way forward.

One more trick you can use when debugging such a problem is adding logging to see what the values are in reality. So for example to display what the payee variable holds, you can add following event: event Log(string str) and call it in the function with emit Log(payee);

  • Okay, I've traced the error back to the deposit(). Question updated – Paradox Sep 19 '18 at 9:51
  • Silly question: Do I have to deploy the escrow Contract? – Paradox Sep 19 '18 at 9:54
  • Yes you do have to deploy it. If it was a library contract you could just use some already deployed one. – Lauri Peltonen Sep 19 '18 at 9:59
  • Added also extra tip for debugging to my answer – Lauri Peltonen Sep 19 '18 at 10:04
  • But I wonder what did I do wrong, I basically used openzeppelin lib and those are tested and audited regularly. Will debug using events tomorrow. – Paradox Sep 19 '18 at 16:19

Your Answer

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

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