// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// SafeMath library for safe arithmetic operations
library SafeMath {
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
uint256 c = a - b;
return c;
}
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: division by zero");
uint256 c = a / b;
return c;
}
}
interface IERC20 {
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
}
contract CoinbasePepe {
using SafeMath for uint256;
// Token metadata
string public constant name = "Coinbase Pepe";
string public constant symbol = "CPEPE";
uint8 public constant decimals = 18;
uint256 public totalSupply;
address public owner;
// Transaction tax
uint256 public transactionTax = 0;
address public taxAddress;
// Balances and allowances
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
// Events
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
// Modifiers
modifier onlyOwner() {
require(msg.sender == owner, "Caller is not the owner");
_;
}
// Constructor
constructor() {
owner = msg.sender;
taxAddress = msg.sender; // Initially, the tax address is set to the owner's address
uint256 initialSupply = 10000000000 * (10 ** uint256(decimals)); // Initial supply: 10,000,000,000 tokens
totalSupply = initialSupply;
balanceOf[msg.sender] = initialSupply;
emit Transfer(address(0), msg.sender, initialSupply);
}
// ERC-20 transfer function with tax
function transfer(address _to, uint256 _value) public returns (bool success) {
uint256 taxAmount = _value.mul(transactionTax).div(100);
uint256 amountAfterTax = _value.sub(taxAmount);
_transfer(msg.sender, _to, amountAfterTax);
if (taxAmount > 0) {
_transfer(msg.sender, taxAddress, taxAmount);
}
return true;
}
// ERC-20 approve function
function approve(address _spender, uint256 _value) public returns (bool success) {
require(_spender != address(0), "Approve to zero address");
allowance[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
// ERC-20 transferFrom function with tax
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_from != address(0), "Transfer from zero address");
require(_to != address(0), "Transfer to zero address");
require(_value <= balanceOf[_from], "Insufficient balance");
require(_value <= allowance[_from][msg.sender], "Allowance exceeded");
allowance[_from][msg.sender] = allowance[_from][msg.sender].sub(_value);
uint256 taxAmount = _value.mul(transactionTax).div(100);
uint256 amountAfterTax = _value.sub(taxAmount);
_transfer(_from, _to, amountAfterTax);
if (taxAmount > 0) {
_transfer(_from, taxAddress, taxAmount);
}
return true;
}
// Internal transfer function
function _transfer(address _from, address _to, uint256 _value) internal {
require(_from != address(0), "Transfer from zero address");
require(_to != address(0), "Transfer to zero address");
require(_value <= balanceOf[_from], "Insufficient balance");
balanceOf[_from] = balanceOf[_from].sub(_value);
balanceOf[_to] = balanceOf[_to].add(_value);
emit Transfer(_from, _to, _value);
}
// Allow the owner to withdraw ETH stuck in the contract
function withdrawETH(uint256 _amount) external onlyOwner {
require(address(this).balance >= _amount, "Insufficient ETH balance");
payable(owner).transfer(_amount);
}
// Allow the owner to withdraw tokens stuck in the contract
function withdrawTokens(address _tokenAddress, uint256 _amount) external onlyOwner {
IERC20 token = IERC20(_tokenAddress);
require(token.balanceOf(address(this)) >= _amount, "Insufficient token balance");
token.transfer(owner, _amount);
}
// Modify the transaction tax
function setTransactionTax(uint256 _tax) external onlyOwner {
require(_tax <= 100, "Tax cannot exceed 100%");
transactionTax = _tax;
}
// Renounce ownership
function renounceOwnership() public onlyOwner {
owner = address(0);
}
// Transfer ownership to another address
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0), "New owner is the zero address");
owner = newOwner;
}
// Allow the contract to receive ETH
receive() external payable {}
}
{
"compilationTarget": {
"Coinbase Pepe.sol": "CoinbasePepe"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_spender","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tax","type":"uint256"}],"name":"setTransactionTax","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"taxAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"transactionTax","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_from","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"withdrawETH","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_tokenAddress","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"withdrawTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]