Dear colleagues of the Ethereum environment,

I'm learning to code Solidity in a intermediate level. Trying to adapt existing old 0.4.19 contract for a experiment of crypto-investment fund. I have a problem when calling the withdrawReward function. Solidity 0.6.8 compiling in Remix.

The contract hast a first function "requestWithdraw" that puts the token-shares in hold:

    function requestWithdraw(uint value) public {
      require(value <= balances[msg.sender]);
      delete holded[msg.sender];
      hold(msg.sender, value);
      emit requestedWithdrawal(msg.sender, value);

Made a transaction calling 100000000 tokens (8 decimals). And tested lower amounts too.

And later on, after the hold time, another function can be call for the withdrawal of the corresponding reward in ether:

    function withdrawReward() external {
        uint i = 0;
        uint256 ethAmount = 0;
        uint256 len = holded[msg.sender].length;
        while (i <= len - 1){
            if (block.number -  holded[msg.sender].time[i] > holdTime && block.number -  holded[msg.sender].time[i] < holdMax){
                ethAmount += tokenPrice * holded[msg.sender].amount[i];
        require(ethAmount > 0);
        emit LogWithdrawal(msg.sender, ethAmount);
        totalSupply = totalSupply.sub(requestWithdraws[msg.sender]);
        balances[msg.sender] = balances[msg.sender].sub(requestWithdraws[msg.sender]);
        contractBalance = address(this).balance.sub(ethAmount);
        emit Transfer(msg.sender, address(this), requestWithdraws[msg.sender]);
        delete holded[msg.sender];

It already have the enough amount of tokens in hold; ether in the contract and seems to be all in its position. But I get this revert error:

transact to DynamicCryptoFund.withdrawReward errored: VM error: revert.
revert  The transaction has been reverted to the initial state.
Note: The called function should be payable if you send value and the value you send should be less than your current balance.  Debug the transaction to get more information
 status     0x0 Transaction mined but execution failed

You can review the full contract's code in my github: https://github.com/ecofintech/dynamic-diverse-cryptofund/blob/master/DynamicCryptoFund-beta.sol

Any feedback is very welcome too.


  • I suggest you remove functionality and try again until you can pinpoint the exact line which causes the revert Commented May 31, 2020 at 13:43
  • thanks.Doig that I arrived at the problem at lines ` require(ethAmount > 0); require(ethAmount>=(tokenPrice*requestWithdraws[msg.sender]));`
    – Ecofintech
    Commented Jun 1, 2020 at 0:13

1 Answer 1


Really I cannot fully understand that complex math function...

If I comment lines

        require(ethAmount > 0);

It works. But sure Im missing something. This require is related with this "hold" function:

    function hold(address _to, uint256 _value) internal {

That points to:

    mapping (address => timeHold) holded;

    struct timeHold{
        uint256[] amount;
        uint256[] time;
        uint256 length;

Does anyone understand it better? Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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