Description:
ERC20 token contract with 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.30;
contract SecuryWalletToken {
string public constant name = "Secury Wallet";
string public constant symbol = "SECURY";
uint8 public constant decimals = 18;
uint256 private _totalSupply;
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
address public owner;
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
constructor() {
owner = msg.sender;
_mint(msg.sender, 1_000_000_000 * 10**decimals);
}
modifier onlyOwner() {
require(msg.sender == owner, "Not owner");
_;
}
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0), "Zero address");
owner = newOwner;
}
// --- ERC20 Core ---
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
function balanceOf(address account) public view returns (uint256) {
return _balances[account];
}
function transfer(address to, uint256 amount) public returns (bool) {
_transfer(msg.sender, to, amount);
return true;
}
function allowance(address _owner, address spender) public view returns (uint256) {
return _allowances[_owner][spender];
}
function approve(address spender, uint256 amount) public returns (bool) {
_approve(msg.sender, spender, amount);
return true;
}
function transferFrom(address from, address to, uint256 amount) public returns (bool) {
_spendAllowance(from, msg.sender, amount);
_transfer(from, to, amount);
return true;
}
function burn(uint256 amount) public {
_burn(msg.sender, amount);
}
// --- Internals ---
function _transfer(address from, address to, uint256 amount) internal {
require(from != address(0), "Transfer from zero");
require(to != address(0), "Transfer to zero");
require(_balances[from] >= amount, "Insufficient balance");
_balances[from] -= amount;
_balances[to] += amount;
emit Transfer(from, to, amount);
}
function _mint(address account, uint256 amount) internal {
require(account != address(0), "Mint to zero");
_totalSupply += amount;
_balances[account] += amount;
emit Transfer(address(0), account, amount);
}
function _burn(address account, uint256 amount) internal {
require(account != address(0), "Burn from zero");
require(_balances[account] >= amount, "Insufficient balance");
_balances[account] -= amount;
_totalSupply -= amount;
emit Transfer(account, address(0), amount);
}
// Fixed: Renamed parameter from `owner` to `_owner`
function _approve(address _owner, address spender, uint256 amount) internal {
require(_owner != address(0), "Approve from zero");
require(spender != address(0), "Approve to zero");
_allowances[_owner][spender] = amount;
emit Approval(_owner, spender, amount);
}
// Fixed: Updated to use `_owner`
function _spendAllowance(address _owner, address spender, uint256 amount) internal {
uint256 currentAllowance = allowance(_owner, spender);
require(currentAllowance >= amount, "Insufficient allowance");
_approve(_owner, spender, currentAllowance - amount);
}
}
Submitted on: 2025-10-03 18:33:50
Comments
Log in to comment.
No comments yet.