distributed_exchange_truffle_class_3 icon indicating copy to clipboard operation
distributed_exchange_truffle_class_3 copied to clipboard

depositToken function is not working

Open itwolfsolutions opened this issue 6 years ago • 1 comments

    //////////////////////////////////
    // DEPOSIT AND WITHDRAWAL TOKEN //
    //////////////////////////////////
    function depositToken(string symbolName, uint amount)  {
        uint8 symbolNameIndex = getSymbolIndexOrThrow(symbolName);
        require(tokens[symbolNameIndex].tokenContract != address(0));

        ERC20Interface token = ERC20Interface(tokens[symbolNameIndex].tokenContract);

        require(token.transferFrom(msg.sender, address(this), amount) == true);
        require(tokenBalanceForAddress[msg.sender][symbolNameIndex] + amount >= tokenBalanceForAddress[msg.sender][symbolNameIndex]);
        tokenBalanceForAddress[msg.sender][symbolNameIndex] += amount;
        DepositForTokenReceived(msg.sender, symbolNameIndex, amount, now);
    }

I see the following error on Remix transact to Exchange.depositToken errored: VM error: revert. revert The transaction has been reverted to the initial state. Note: The constructor should be payable if you send value. Debug the transaction to get more information.

itwolfsolutions avatar Mar 15 '18 09:03 itwolfsolutions

The Deposit function is working perfectly fine for me. The error is misleading imho.

A typical mistake is to forget to add the tokens to the exchange first, or approve the exchange as the receiver of the tokens. Then an exception is triggered which in turn throws this error message.

Try to debug the message and see where exactly it gets stuck, as the error says.

tomw1808 avatar Mar 15 '18 10:03 tomw1808