Contract Source Code:
File 1 of 1 : SimpleICO.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.24; contract SimpleICO { address public owner; uint256 public tokenPrice = 0.001 ether; uint256 public tokensSold; uint256 public constant TOTAL_SUPPLY = 1000000 * 10**18; // 1 million tokens mapping(address => uint256) public balances; event TokensPurchased(address buyer, uint256 amount); constructor() { owner = msg.sender; balances[address(this)] = TOTAL_SUPPLY; } modifier onlyOwner() { require(msg.sender == owner, "Only owner can call this function"); _; } function buyTokens() public payable { require(msg.value > 0, "Send ETH to buy tokens"); require(balances[address(this)] > 0, "No tokens available"); uint256 tokenAmount = (msg.value * 10**18) / tokenPrice; require(tokenAmount <= balances[address(this)], "Not enough tokens available"); balances[address(this)] -= tokenAmount; balances[msg.sender] += tokenAmount; tokensSold += tokenAmount; emit TokensPurchased(msg.sender, tokenAmount); } function withdrawFunds() public onlyOwner { (bool success, ) = owner.call{value: address(this).balance}(""); require(success, "Payment failed."); } function getBalance(address account) public view returns (uint256) { return balances[account]; } function getRemainingTokens() public view returns (uint256) { return balances[address(this)]; } }
Please enter a contract address above to load the contract details and source code.
Please DO NOT store any passwords or private keys here. A private note (up to 100 characters) can be saved and is useful for transaction tracking.
This website uses cookies to improve your experience. By continuing to use this website, you agree to its Terms and Privacy Policy.