Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

depositToken function is not working #2

Open
itwolfsolutions opened this issue Mar 15, 2018 · 1 comment
Open

depositToken function is not working #2

itwolfsolutions opened this issue Mar 15, 2018 · 1 comment

Comments

@itwolfsolutions
Copy link

    //////////////////////////////////
    // 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.

@tomw1808
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants