0

Hi i have copied the etherdelta smart contract code.All is working fine.I can withdraw tokens from the snart contract to my personal wallet. By reading the code what i understand is,the depositToken method is like allowing the contract to send tokens from my wallet on behalf of me.But this is not working.when i click deoosit,the transaction gets reverted. I guess its some issue with the approve() function.Please can someone clear that for me?

    function depositToken(address token, uint amount) {
    //remember to call Token(address).approve(this, amount) or this contract will not be able to do the transfer on your behalf.
    if (msg.value>0 || token==0) throw;
    if (!Token(token).transferFrom(msg.sender, this, amount)) throw;
    tokens[token][msg.sender] = safeAdd(tokens[token][msg.sender], amount);
    Deposit(token, msg.sender, amount, tokens[token][msg.sender]);
  }

//remember to call Token(address).approve(this, amount) or this contract will not be able to do the transfer on your behalf.

What this line means?

1

Are you calling the approve function on the token contract before calling depositToken? If you don't, then the transferFrom will fail since the contract isn't authorized to move any of your tokens.

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.