// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; contract TokenPresale { address public owner; uint256 public tokenPrice = 0.01 ether; // Example price uint256 public tokensSold; event Sold(address buyer, uint256 amount); constructor() { owner = msg.sender; } function buyTokens() public payable { require(msg.value >= tokenPrice, "Insufficient ETH sent"); uint256 tokenAmount = msg.value / tokenPrice; tokensSold += tokenAmount; emit Sold(msg.sender, tokenAmount); } function endSale() public { require(msg.sender == owner, "Only owner can end the sale"); payable(owner).transfer(address(this).balance); } }