Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
- Contract name:
- Presale
- Optimization enabled
- true
- Compiler version
- v0.8.19+commit.7dd6d404
- Optimization runs
- 200
- EVM Version
- default
- Verified at
- 2024-02-16T01:01:21.059849Z
Constructor Arguments
0x00000000000000000000000020f72dcf9141e1b6014c835b6d0709e32d806f10
Arg [0] (address) : 0x20f72dcf9141e1b6014c835b6d0709e32d806f10
contracts/Presale.sol
// SPDX-License-Identifier: MIT
// File @openzeppelin/contracts/token/ERC20/IERC20.sol@v4.8.0
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)
pragma solidity 0.8.19;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when 'value' tokens are moved from one account ('from') to
* another ('to').
*
* Note that 'value' may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a 'spender' for an 'owner' is set by
* a call to {approve}. 'value' is the new allowance.
*/
event Approval(
address indexed owner,
address indexed spender,
uint256 value
);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by 'account'.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves 'amount' tokens from the caller's account to 'to'.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that 'spender' will be
* allowed to spend on behalf of 'owner' through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(
address owner,
address spender
) external view returns (uint256);
/**
* @dev Sets 'amount' as the allowance of 'spender' over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves 'amount' tokens from 'from' to 'to' using the
* allowance mechanism. 'amount' is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
}
// File @openzeppelin/contracts/utils/Context.sol@v4.8.0
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
// File @openzeppelin/contracts/access/Ownable.sol@v4.8.0
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* 'onlyOwner', which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* 'onlyOwner' functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account ('newOwner').
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(
newOwner != address(0),
"Ownable: new owner is the zero address"
);
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account ('newOwner').
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
contract Presale is Ownable {
uint256 public tokenPrice = 7777 ether; // price of each token in ETH
// uint256 public hardCap = 49772800 ether; // hard cap in ETH
uint256 public hardCap = 7777 ether; // hard cap in ETH
uint256 public filled = 0 ether; // hard cap in ETH
address public tokenAddress; // address of the token contract
mapping(address => uint256) public tokenBalances; // keep track of the number of tokens each address holds
mapping(address => uint256) public invested; // keep track of the amount of ETH each address has invested
mapping(address => bool) public is_buyer; // mapping for checking if an address has bought tokens
event TokenPurchase(address indexed buyer, uint256 amount); // emit an event when tokens are purchased
event Claim(address indexed buyer, uint256 amount); // emit an event when tokens are claimed
constructor(address _tokenAddress) {
tokenAddress = _tokenAddress;
}
receive() external payable {}
function setTokenPrice(uint256 _tokenPrice) public onlyOwner {
tokenPrice = _tokenPrice;
}
function setTokenAddress(address _tokenAddress) public onlyOwner {
tokenAddress = _tokenAddress;
}
function buyTokens() public payable {
require(
is_buyer[msg.sender] == false,
"You have already bought tokens"
);
require(msg.value == 7777 ether, "Wrong amount of ETH sent");
uint256 amount = (msg.value / tokenPrice) * 10 ** 18;
tokenBalances[msg.sender] += amount;
invested[msg.sender] += msg.value;
is_buyer[msg.sender] = true;
filled += msg.value;
emit TokenPurchase(msg.sender, amount);
}
function claimTokens() public {
require(filled >= hardCap, "Claim is not yet enabled");
uint256 amount = tokenBalances[msg.sender];
require(amount > 0, "not have tokens to claim");
tokenBalances[msg.sender] = 0;
IERC20(tokenAddress).transfer(msg.sender, amount);
emit Claim(msg.sender, amount);
}
// function to withdraw ETH from the contract
function withdraw() public onlyOwner {
(bool success, ) = payable(owner()).call{value: address(this).balance}(
""
);
require(success, "Transfer failed.");
}
// function to withdraw ERC20 tokens from the contract
function withdrawToken() public onlyOwner {
IERC20 token = IERC20(tokenAddress);
uint256 balance = token.balanceOf(address(this));
token.transfer(owner(), balance);
}
}
Compiler Settings
{"outputSelection":{"*":{"*":["*"],"":["*"]}},"optimizer":{"runs":200,"enabled":true},"libraries":{}}
Contract ABI
[{"type":"constructor","stateMutability":"nonpayable","inputs":[{"type":"address","name":"_tokenAddress","internalType":"address"}]},{"type":"event","name":"Claim","inputs":[{"type":"address","name":"buyer","internalType":"address","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"OwnershipTransferred","inputs":[{"type":"address","name":"previousOwner","internalType":"address","indexed":true},{"type":"address","name":"newOwner","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"TokenPurchase","inputs":[{"type":"address","name":"buyer","internalType":"address","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"function","stateMutability":"payable","outputs":[],"name":"buyTokens","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"claimTokens","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"filled","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"hardCap","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"invested","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"is_buyer","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceOwnership","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setTokenAddress","inputs":[{"type":"address","name":"_tokenAddress","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setTokenPrice","inputs":[{"type":"uint256","name":"_tokenPrice","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"tokenAddress","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"tokenBalances","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"tokenPrice","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"newOwner","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"withdraw","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"withdrawToken","inputs":[]},{"type":"receive","stateMutability":"payable"}]
Contract Creation Code
0x60806040526901a5978e47b024e400006001556901a5978e47b024e40000600255600060035534801561003157600080fd5b50604051610b52380380610b52833981016040819052610050916100ce565b6100593361007e565b600480546001600160a01b0319166001600160a01b03929092169190911790556100fe565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6000602082840312156100e057600080fd5b81516001600160a01b03811681146100f757600080fd5b9392505050565b610a458061010d6000396000f3fe6080604052600436106100f65760003560e01c8063715018a61161008a578063ca628c7811610059578063ca628c78146102ae578063d0febe4c146102c3578063f2fde38b146102cb578063fb86a404146102eb57600080fd5b8063715018a6146102315780637ff9b596146102465780638da5cb5b1461025c5780639d76ea581461028e57600080fd5b8063523fba7f116100c6578063523fba7f146101935780635c0133d9146101ce57806366b3f6bf146101e45780636a61e5fc1461021157600080fd5b8062f3cb211461010257806326a4e8d2146101475780633ccfd60b1461016957806348c54b9d1461017e57600080fd5b366100fd57005b600080fd5b34801561010e57600080fd5b5061013261011d366004610923565b60076020526000908152604090205460ff1681565b60405190151581526020015b60405180910390f35b34801561015357600080fd5b50610167610162366004610923565b610301565b005b34801561017557600080fd5b5061016761032b565b34801561018a57600080fd5b506101676103d1565b34801561019f57600080fd5b506101c06101ae366004610923565b60056020526000908152604090205481565b60405190815260200161013e565b3480156101da57600080fd5b506101c060035481565b3480156101f057600080fd5b506101c06101ff366004610923565b60066020526000908152604090205481565b34801561021d57600080fd5b5061016761022c366004610953565b610544565b34801561023d57600080fd5b50610167610551565b34801561025257600080fd5b506101c060015481565b34801561026857600080fd5b506000546001600160a01b03165b6040516001600160a01b03909116815260200161013e565b34801561029a57600080fd5b50600454610276906001600160a01b031681565b3480156102ba57600080fd5b50610167610565565b610167610678565b3480156102d757600080fd5b506101676102e6366004610923565b610803565b3480156102f757600080fd5b506101c060025481565b610309610879565b600480546001600160a01b0319166001600160a01b0392909216919091179055565b610333610879565b600080546040516001600160a01b039091169047908381818185875af1925050503d8060008114610380576040519150601f19603f3d011682016040523d82523d6000602084013e610385565b606091505b50509050806103ce5760405162461bcd60e51b815260206004820152601060248201526f2a3930b739b332b9103330b4b632b21760811b60448201526064015b60405180910390fd5b50565b60025460035410156104255760405162461bcd60e51b815260206004820152601860248201527f436c61696d206973206e6f742079657420656e61626c6564000000000000000060448201526064016103c5565b33600090815260056020526040902054806104825760405162461bcd60e51b815260206004820152601860248201527f6e6f74206861766520746f6b656e7320746f20636c61696d000000000000000060448201526064016103c5565b336000818152600560205260408082209190915560048054915163a9059cbb60e01b815290810192909252602482018390526001600160a01b03169063a9059cbb906044016020604051808303816000875af11580156104e6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061050a919061096c565b5060405181815233907f47cee97cb7acd717b3c0aa1435d004cd5b3c8c57d70dbceb4e4458bbd60e39d4906020015b60405180910390a250565b61054c610879565b600155565b610559610879565b61056360006108d3565b565b61056d610879565b600480546040516370a0823160e01b815230928101929092526001600160a01b03169060009082906370a0823190602401602060405180830381865afa1580156105bb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105df919061098e565b9050816001600160a01b031663a9059cbb6106026000546001600160a01b031690565b6040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602481018490526044016020604051808303816000875af115801561064f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610673919061096c565b505050565b3360009081526007602052604090205460ff16156106d85760405162461bcd60e51b815260206004820152601e60248201527f596f75206861766520616c726561647920626f7567687420746f6b656e73000060448201526064016103c5565b346901a5978e47b024e40000146107315760405162461bcd60e51b815260206004820152601860248201527f57726f6e6720616d6f756e74206f66204554482073656e74000000000000000060448201526064016103c5565b60006001543461074191906109bd565b61075390670de0b6b3a76400006109df565b336000908152600560205260408120805492935083929091906107779084906109fc565b9091555050336000908152600660205260408120805434929061079b9084906109fc565b9091555050336000908152600760205260408120805460ff19166001179055600380543492906107cc9084906109fc565b909155505060405181815233907ff4b351c7293f3c20fc9912c61adbe9823a6de3162bde18c98eb6feeae232f86190602001610539565b61080b610879565b6001600160a01b0381166108705760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016103c5565b6103ce816108d3565b6000546001600160a01b031633146105635760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016103c5565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60006020828403121561093557600080fd5b81356001600160a01b038116811461094c57600080fd5b9392505050565b60006020828403121561096557600080fd5b5035919050565b60006020828403121561097e57600080fd5b8151801515811461094c57600080fd5b6000602082840312156109a057600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b6000826109da57634e487b7160e01b600052601260045260246000fd5b500490565b80820281158282048414176109f6576109f66109a7565b92915050565b808201808211156109f6576109f66109a756fea2646970667358221220f27614c57e8d7988d870f27201b782c653ca15f8318fd5cb545377733ac9e0dc64736f6c6343000813003300000000000000000000000020f72dcf9141e1b6014c835b6d0709e32d806f10
Deployed ByteCode
0x6080604052600436106100f65760003560e01c8063715018a61161008a578063ca628c7811610059578063ca628c78146102ae578063d0febe4c146102c3578063f2fde38b146102cb578063fb86a404146102eb57600080fd5b8063715018a6146102315780637ff9b596146102465780638da5cb5b1461025c5780639d76ea581461028e57600080fd5b8063523fba7f116100c6578063523fba7f146101935780635c0133d9146101ce57806366b3f6bf146101e45780636a61e5fc1461021157600080fd5b8062f3cb211461010257806326a4e8d2146101475780633ccfd60b1461016957806348c54b9d1461017e57600080fd5b366100fd57005b600080fd5b34801561010e57600080fd5b5061013261011d366004610923565b60076020526000908152604090205460ff1681565b60405190151581526020015b60405180910390f35b34801561015357600080fd5b50610167610162366004610923565b610301565b005b34801561017557600080fd5b5061016761032b565b34801561018a57600080fd5b506101676103d1565b34801561019f57600080fd5b506101c06101ae366004610923565b60056020526000908152604090205481565b60405190815260200161013e565b3480156101da57600080fd5b506101c060035481565b3480156101f057600080fd5b506101c06101ff366004610923565b60066020526000908152604090205481565b34801561021d57600080fd5b5061016761022c366004610953565b610544565b34801561023d57600080fd5b50610167610551565b34801561025257600080fd5b506101c060015481565b34801561026857600080fd5b506000546001600160a01b03165b6040516001600160a01b03909116815260200161013e565b34801561029a57600080fd5b50600454610276906001600160a01b031681565b3480156102ba57600080fd5b50610167610565565b610167610678565b3480156102d757600080fd5b506101676102e6366004610923565b610803565b3480156102f757600080fd5b506101c060025481565b610309610879565b600480546001600160a01b0319166001600160a01b0392909216919091179055565b610333610879565b600080546040516001600160a01b039091169047908381818185875af1925050503d8060008114610380576040519150601f19603f3d011682016040523d82523d6000602084013e610385565b606091505b50509050806103ce5760405162461bcd60e51b815260206004820152601060248201526f2a3930b739b332b9103330b4b632b21760811b60448201526064015b60405180910390fd5b50565b60025460035410156104255760405162461bcd60e51b815260206004820152601860248201527f436c61696d206973206e6f742079657420656e61626c6564000000000000000060448201526064016103c5565b33600090815260056020526040902054806104825760405162461bcd60e51b815260206004820152601860248201527f6e6f74206861766520746f6b656e7320746f20636c61696d000000000000000060448201526064016103c5565b336000818152600560205260408082209190915560048054915163a9059cbb60e01b815290810192909252602482018390526001600160a01b03169063a9059cbb906044016020604051808303816000875af11580156104e6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061050a919061096c565b5060405181815233907f47cee97cb7acd717b3c0aa1435d004cd5b3c8c57d70dbceb4e4458bbd60e39d4906020015b60405180910390a250565b61054c610879565b600155565b610559610879565b61056360006108d3565b565b61056d610879565b600480546040516370a0823160e01b815230928101929092526001600160a01b03169060009082906370a0823190602401602060405180830381865afa1580156105bb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105df919061098e565b9050816001600160a01b031663a9059cbb6106026000546001600160a01b031690565b6040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602481018490526044016020604051808303816000875af115801561064f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610673919061096c565b505050565b3360009081526007602052604090205460ff16156106d85760405162461bcd60e51b815260206004820152601e60248201527f596f75206861766520616c726561647920626f7567687420746f6b656e73000060448201526064016103c5565b346901a5978e47b024e40000146107315760405162461bcd60e51b815260206004820152601860248201527f57726f6e6720616d6f756e74206f66204554482073656e74000000000000000060448201526064016103c5565b60006001543461074191906109bd565b61075390670de0b6b3a76400006109df565b336000908152600560205260408120805492935083929091906107779084906109fc565b9091555050336000908152600660205260408120805434929061079b9084906109fc565b9091555050336000908152600760205260408120805460ff19166001179055600380543492906107cc9084906109fc565b909155505060405181815233907ff4b351c7293f3c20fc9912c61adbe9823a6de3162bde18c98eb6feeae232f86190602001610539565b61080b610879565b6001600160a01b0381166108705760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016103c5565b6103ce816108d3565b6000546001600160a01b031633146105635760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016103c5565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60006020828403121561093557600080fd5b81356001600160a01b038116811461094c57600080fd5b9392505050565b60006020828403121561096557600080fd5b5035919050565b60006020828403121561097e57600080fd5b8151801515811461094c57600080fd5b6000602082840312156109a057600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b6000826109da57634e487b7160e01b600052601260045260246000fd5b500490565b80820281158282048414176109f6576109f66109a7565b92915050565b808201808211156109f6576109f66109a756fea2646970667358221220f27614c57e8d7988d870f27201b782c653ca15f8318fd5cb545377733ac9e0dc64736f6c63430008130033