I'm having a trouble trying to solve this task: I created a very simple smart contract that should call a function in the external smart contract and transfer tokens. Here's my contract code:
pragma solidity >=0.7.0 <0.9.0;
contract TestContract {
address owner;
modifier onlyowner {
require(owner == msg.sender);
_;
}
function withdraw(address usdtContractAddress, address receiver, uint256 amount) public {
bytes memory payload = abi.encodeWithSignature("transfer(address, uint256)", receiver, amount);
(bool success, ) = usdtContractAddress.call(payload);
require(success);
}
}
So basically this contract calls transfer function in the external contract (USDT).
I've deployed my contract and sent some usdt tokens to this contract address.
So since the contract address is the owner of that tokens in usdt contract I assume I can call transfer method from my contract and send these tokens to any address.
The whole idea is to pay gas from the address which calls withdraw method in my contract and contract as the owner of tokens will transfer tokens to another address.
The issue is once I'm trying to run this withdraw function the transaction is being reverted.
Just an example: https://ropsten.etherscan.io/tx/0x4e0e782dee6ee256f8038dd249970ccd5bb5328333bc4c481649ec730644cdf2
I'm not a solidity developer so perhaps my mistake is obvious, but I can't find the reason why it doesn't work. Any advice?
By the way, when I'm trying to debug this transaction in remix I see that success is true, so It means the function call was success?
