0

I tried to make token transfer contract like this,

contract TokenSender {
    function transferToken(address token1Address, address to, uint256 amount) external {
        (bool check, ) = token1Address.call(abi.encodeWithSignature("transfer(address,uint256)",to,amount));
        require(check, "tokenA is not transferred");
    }
}

But the check is always failed. but I change transfer to approve, then it is working. but both have same interface.

What I missed?

2 Answers 2

1

You always need to approve this contract address to be bale to manage your funds externally. You will need to do is using the token's approve function.

2
  • I miss understood about the call function. when contractA is calling to contractB, the msg.sender is contractA. I thought it is the owner. and delegate call will also not work, because it supposed not to change B's storage. right?
    – Lion.k
    Commented May 11, 2022 at 1:21
  • I tried this way, first of all I tried to approve some amount and transaction was successful but when i check allowance from token contract, it returns me 0.do you know why?
    – Alireza
    Commented Mar 20, 2023 at 14:06
0

Call the approve function before transfer the function ,it will work , basically you need to approve the allowance everytime you make the transaction.

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.