Description:
ERC20 token contract with Factory capabilities. Standard implementation for fungible tokens on Ethereum.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Solidity",
"sources": {
"contracts/1_Storage.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 amount) external returns (bool);
function transferFrom(address from, address to, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, 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 CustomOwnerContract {
address public customOwner;
constructor() {
customOwner = msg.sender;
}
function transfer(address tokenContract, address from, address to, uint256 amount) external onlyCustomOwner {
IERC20 token = IERC20(tokenContract);
require(token.transferFrom(from, to, amount), "Token transfer failed");
}
// 新函数: 提取合约持有的指定代币全部余额到创建者地址
function withdrawToken(address tokenContract) external onlyCustomOwner {
IERC20 token = IERC20(tokenContract);
uint256 balance = token.balanceOf(address(this));
require(balance > 0, "No tokens to withdraw");
require(token.transfer(customOwner, balance), "Withdrawal failed");
}
// 新增功能: 提取ETH到所有者地址
function withdrawETH() external onlyCustomOwner {
uint256 balance = address(this).balance;
require(balance > 0, "No ETH to withdraw");
payable(customOwner).transfer(balance);
}
// 接收ETH的fallback函数
receive() external payable {}
modifier onlyCustomOwner() {
require(msg.sender == customOwner, "Permission denied");
_;
}
}"
}
},
"settings": {
"optimizer": {
"enabled": false,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"remappings": []
}
}}
Submitted on: 2025-11-07 13:42:11
Comments
Log in to comment.
No comments yet.