This approves the contract to transfer an amount of usdt from itself:
And this returns the amount of usdt that the contract is allowed to transfer from the sender:
Now, obviously, the sender in this case is not the contract, but the account that you’re using in order to sign and execute each one of these transactions.
The above is just to strictly answer your question.
In order to give you some further help, note that the
usdt.approve(address(this),amount) part is completely redundant.
An account doesn’t need approval to transfer funds from itself; it only needs approval to transfer funds from other accounts.
More generally, you seem to be missing the whole point in the
transferFrom scheme, which consists of the following two transactions:
tokenContract.approve(someContract), in order to allow
someContract to transfer funds from
someContract.someFunc, which internally executes
tokenContract.transferFrom(entity) in order to transfer funds from
entity to somewhere (either to
someContract itself, or to some other account)
entity can be either an externally-owned account (aka wallet), or a smart-contract account.
In short, your off-chain script (assuming that this is how you are trying to execute the process), should look more or less like this:
Deploy an instance of
Sign and send with
usdt.allowance(yourAccount, callContract.address) returns
Again - all of the above should be executed from your off-chain script, NOT as part of your contract.
At this point,
callContract should be able to transfer up to
amount usdt from
yourAccount to any other account, so you can add a function in this contract, which will internally call
usdt.transferFrom in order to execute the desired transfer.
On top of that, you may have realized by now that both of the functions currently implemented in your contract are redundant:
approveUsdt, because this approval should be executed outside the contract
getApprovedBalance , because this query can be executed outside the contract