when i am going to call approve function of erc20 contract.log prints tokenOwner and tokenSpender address same which is contract address msg.sender returns contract address. but i want tokenWner = caller address and tokenSpender = contract address please help.

THis is erc20 method

 function approve(address spender, uint256 tokens) public returns (bool success) {
    allowed[msg.sender][spender] = tokens;
   emit Approval(msg.sender, spender, tokens);

    return true;

And this is my contract method that is calling token method

 function approve(address token, uint256 _value) public returns (bool) {
 return ERC20Interface(token).approve(this, _value);
  • post your javescript code, and maybe the approve funtion of your smart contract
    – Majd TL
    Commented Nov 27, 2019 at 11:05
  • @MajdTL here is my code in erc20 (msg.sender) become my contract address Commented Nov 27, 2019 at 11:20
  • try to use delegated calls, however that is not the best praxis, has risk, and the owner of the token should call the first approve method directly, both are public functions. ethereum.stackexchange.com/questions/8120/…
    – Majd TL
    Commented Nov 27, 2019 at 12:14
  • Already i tried with delegate call it working fine with approve. but when i call allowance it returning me 0 approval. Commented Nov 27, 2019 at 12:42
  • you call allowance with delegated call? delegate call does not provide a return value or exception
    – Majd TL
    Commented Nov 27, 2019 at 15:07

1 Answer 1


The users who is spending tokens is the one to approve the contract.

The contract cannot appoint itself to spend tokens from someone else's wallet.

Hope it helps.

  • you are right. but when i call approve function from my contract than msg.sender should be caller address but right now it is contract address. and i want to approve my contract from caller.and that caller already have tokens. Commented Nov 27, 2019 at 13:24
  • The msg.sender should be your contract, in that case, which is not what you want, because msg.sender is always the inner-most caller, which is your contract. The caller needs to approve directly, not through your contract. Commented Nov 28, 2019 at 2:00
  • in that case what should i do? Commented Nov 28, 2019 at 4:44
  • 1
    I suspect maybe you misunderstand the flow. The user calls approve in the token contract and then calls a function in your contract to do something and pull the payment. The two steps on the user side can be coordinated by the user-facing UI. Commented Nov 28, 2019 at 17:29
  • 1
    @lovechawda you have the address of that erc20 token contract and the abi is always the same cause it is a standard
    – Majd TL
    Commented Nov 29, 2019 at 9:40

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.