Is there any guide or code that can serve as an example to implement the functionality where a smart contract receives and sends USDT to other addresses.
I appreciate your help
USDT is the USD-pegged stablecoin issued by Tether on the TRON network. The token will be able to complete issuance, holding and transfer via smart contract on TRON, with a completely free and transparent process, zero transfer fee, and instant delivery; it will also be able to write programs that are highly expansible ...
This contract now meets the Owner model where it checks if address calling the function is the owner before allowing it to proceed further. So that's it for this simple smart contract that allows money to be sent to it, and only allows the owner to withdraw all the money from the smart contract.
What's the smart contract address for Tether USD (BEP-20)? Tether USD (BEP-20)'s smart contract address is 0x55d398326f99059ff775485246999027b3197955.
The token balance is stored in the token contract (in this case USDT), not in yours. So sending tokens is a straightforward process - you just execute the correct function on the token contract. Mind that your contract needs to hold at least the amount it's about to send, otherwise the transaction would revert.
pragma solidity ^0.8;
interface IERC20 {
function transfer(address _to, uint256 _value) external returns (bool);
// don't need to define other functions, only using `transfer()` in this case
}
contract MyContract {
// Do not use in production
// This function can be executed by anyone
function sendUSDT(address _to, uint256 _amount) external {
// This is the mainnet USDT contract address
// Using on other networks (rinkeby, local, ...) would fail
// - there's no contract on this address on other networks
IERC20 usdt = IERC20(address(0xdAC17F958D2ee523a2206206994597C13D831ec7));
// transfers USDT that belong to your contract to the specified address
usdt.transfer(_to, _amount);
}
}
But because the balance is stored in the external contract, you can't just make a user send you tokens by executing a function in your contract. See my other answer that shows an example how this could be misused if it were possible (just replace approve
to transfer
, but the logic is the same).
Some token standards (such as ERC-1155 or ERC-721) allow sending a hook to your contract when your contract receives tokens. The hook function names and required parameters are in the linked documents. But whether the token contract sends you a hook, that depends on
fallback()
which would work in some cases)You can ask your users to approve some USDT to be spent by your address, and then your contract can execute the transferFrom()
function of the USDT contract (where the "from" is the user who approved you to spend their tokens). However, the approval needs to be done outside of your contract, as the linked other answer suggests.
You can also have an off-chain app that listens to event logs emitted by the token contract (in your case Transfer()
event on the USDT contract). The event logs contain the transfer information including the receiver and amount. So your (off-chain) app can filter only events where your address is the receiver, and perform some action when it handles the event log.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With