In exchange contract,With multi token when I call approve function from exchange contract, nor my address and spender get approved. Instead only the exchange address and spender gets approved. Its like when I call approve with spender as my contract address, in token contract it takes msg.sender as my contract address.

How to solve this issue.

With the below code, I tried calling approve function. But that's not a working properly. Kindly prefer a solution for this.

function transfer(address token, uint256 tokens)public payable // deposit perticular token balance to contract address (site address), can depoit multiple token   
    dep_token[msg.sender][token] = safeAdd(dep_token[msg.sender][token], tokens);
    Token(token).transferFrom(msg.sender,address(this), tokens);

function token_withdraw(address token, uint256 tokens)public payable // withdraw perticular token balance from contract to user    
dep_token[msg.sender][token] = safeSub(dep_token[msg.sender][token] , tokens) ;   
Token(token).transfer(msg.sender, tokens);

closed as unclear what you're asking by smarx, Achala Dissanayake, shane, Briomkez, flygoing Mar 16 at 16:15

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


Ask user to approve the exchange contract.

Or personally I added authorized contracts into my multiownable token contract that means that admins approve contracts that could approve to itselves to transfer anybody's tokens. And of course, I add this function into token contract. But this method is much less secure and I think many users could be afraid to use tokens with these functionality.

  • Do token contracts(multi) has to approve exchange contracts address to get placed their token in exchange site? – osiz-blockchain Mar 18 at 4:53
  • Token contracts are also don't approve other contracts(and any other addresses). The token owner only can do it. But as I described my decision, it looks like admins of token contract approve exchange contracts to transfer tokens of any user. – Aleksandr Mar 18 at 6:56

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