TRC20合约,转出代币的代码
区块链开发
2022-10-11
pragma solidity 0.5.16;
interface ITRC20 {
function getOwner() external view returns (address);
function transferToken(address _token,address recipient, uint256 amount) external returns (bool);
}
contract MyContract {
address private _owner;
constructor() public {}
/**
* @dev Returns the TRC token owner.
*/
function getOwner() external view returns (address) {
return owner();
}
function owner() public view returns (address) {
return _owner;
}
function transferToken(address _token,address _to, uint256 _amount) external payable onlyOwner{
// 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
ITRC20 Token = ITRC20(address(_token));
Token.transfer(_to, _amount);
}
}
interface ITRC20 {
function getOwner() external view returns (address);
function transferToken(address _token,address recipient, uint256 amount) external returns (bool);
}
contract MyContract {
address private _owner;
constructor() public {}
/**
* @dev Returns the TRC token owner.
*/
function getOwner() external view returns (address) {
return owner();
}
function owner() public view returns (address) {
return _owner;
}
function transferToken(address _token,address _to, uint256 _amount) external payable onlyOwner{
// 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
ITRC20 Token = ITRC20(address(_token));
Token.transfer(_to, _amount);
}
}