ETH Price: $2,654.69 (+1.62%)

Contract Diff Checker

Contract Name:
SimplePresaleContract

Contract Source Code:

File 1 of 1 : SimplePresaleContract

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

interface IERC20 {
    function transfer(address recipient, uint256 amount) external returns (bool);
}

contract SimplePresaleContract {
    address payable public owner;
    IERC20 public token;
    uint256 public currentStage;

    // Pricing for each stage
    uint256[8] private stagePricing = [700, 770, 847, 932, 1025, 1128, 1241, 1365]; // Prices in some unit, e.g., $0.00700 as 700

    event BuyWithETH(address indexed buyer, uint256 ethAmount, uint256 tokenAmount);

    constructor(address _tokenAddress) {
        owner = payable(msg.sender);
        token = IERC20(_tokenAddress);
    }

    // Fallback function to handle receiving Ether
    receive() external payable {
        uint256 tokensToDistribute = calculateTokenAmount(msg.value);
        require(token.transfer(msg.sender, tokensToDistribute), "Token transfer failed");

        emit BuyWithETH(msg.sender, msg.value, tokensToDistribute);
        forwardFunds();
    }

    function forwardFunds() internal {
        (bool sent, ) = owner.call{value: msg.value}("");
        require(sent, "Failed to send Ether");
    }

    function calculateTokenAmount(uint256 ethAmount) public view returns (uint256) {
        // Calculate token amount based on current stage pricing
        // Ensure conversion rates between ETH and USD, and token decimals are handled correctly
        return ethAmount / stagePricing[currentStage];
    }

    function setCurrentStage(uint256 _stage) external {
        // Add appropriate access control to restrict who can call this function
        require(_stage >= 0 && _stage < stagePricing.length, "Invalid stage");
currentStage = _stage;
}

}

Please enter a contract address above to load the contract details and source code.

Context size (optional):