Description:
ERC20 token contract with Mintable, Burnable capabilities. Standard implementation for fungible tokens on Ethereum.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface ITRC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address) external view returns (uint256);
function allowance(address owner, address spender) external view returns (uint256);
function transfer(address to, uint256 amount) external returns (bool);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address from, address to, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
contract USDT is ITRC20 {
string public constant name = "Tether USD";
string public constant symbol = "USDT";
string public constant description = "This token is only for testing and educational purposes.";
uint8 public constant decimals = 6;
uint256 private _totalSupply;
mapping(address => uint256) private _balanceOf;
mapping(address => mapping(address => uint256)) private _allowance;
address public owner;
modifier onlyOwner() {
require(msg.sender == owner, "Only owner can call this function");
_;
}
constructor() {
owner = msg.sender;
_totalSupply = 1_000_000 * 10**uint256(decimals);
_balanceOf[msg.sender] = _totalSupply;
emit Transfer(address(0), msg.sender, _totalSupply);
}
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
function balanceOf(address account) public view override returns (uint256) {
return _balanceOf[account];
}
function allowance(address owner_, address spender) public view override returns (uint256) {
return _allowance[owner_][spender];
}
function transfer(address to, uint256 amount) public override returns (bool) {
require(to != address(0), "Invalid recipient");
uint256 senderBalance = _balanceOf[msg.sender];
require(senderBalance >= amount, "Insufficient balance");
unchecked {
_balanceOf[msg.sender] = senderBalance - amount;
}
_balanceOf[to] += amount;
emit Transfer(msg.sender, to, amount);
return true;
}
function approve(address spender, uint256 amount) public override returns (bool) {
require(spender != address(0), "Invalid spender");
_allowance[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
function transferFrom(address from, address to, uint256 amount) public override returns (bool) {
require(from != address(0), "Invalid sender");
require(to != address(0), "Invalid recipient");
uint256 fromBalance = _balanceOf[from];
uint256 currentAllowance = _allowance[from][msg.sender];
require(fromBalance >= amount, "Insufficient balance");
require(currentAllowance >= amount, "Allowance too low");
unchecked {
_balanceOf[from] = fromBalance - amount;
_allowance[from][msg.sender] = currentAllowance - amount;
}
_balanceOf[to] += amount;
emit Transfer(from, to, amount);
return true;
}
function mint(address to, uint256 amount) external onlyOwner returns (bool) {
require(to != address(0), "Invalid address");
_totalSupply += amount;
_balanceOf[to] += amount;
emit Transfer(address(0), to, amount);
return true;
}
function burn(uint256 amount) external returns (bool) {
uint256 accountBalance = _balanceOf[msg.sender];
require(accountBalance >= amount, "Burn amount exceeds balance");
unchecked {
_balanceOf[msg.sender] = accountBalance - amount;
_totalSupply -= amount;
}
emit Transfer(msg.sender, address(0), amount);
return true;
}
}
Submitted on: 2025-10-18 11:08:43
Comments
Log in to comment.
No comments yet.