Skip to content
Verified contractPartial

WDXSale

Address0xec2a00976ad9de72161069bec8eda1df38ec4c31
Balance

0 ETH

 

Transactions

243

 

Compiler

solc 0.5.17

 

Same code

Only this contract

 

Details

Compiler
solc 0.5.17+commit.d19bba13
Language
solidity
Optimization
Yes, 200 runs
License
Not stated
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
10,985,282
Creation transaction
0xf4ffc8ecf4…bf381e2b16

WDXSale.sol

pragma solidity ^0.5.8;

interface IERC20Token {
    function balanceOf(address owner) external returns (uint256);
    function transfer(address to, uint256 amount) external returns (bool);
    function decimals() external returns (uint256);
}

contract WDXSale {
    IERC20Token public tokenContract;  // the token being sold
    uint256 public price;              // the price, in wei, per token
    address owner;

    uint256 public tokensSold;

    event Sold(address buyer, uint256 amount);

    constructor(IERC20Token _tokenContract, uint256 _price) public {
        owner = msg.sender;
        tokenContract = _tokenContract;
        price = _price;
    }

    // Guards against integer overflows
    function safeMultiply(uint256 a, uint256 b) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        } else {
            uint256 c = a * b;
            assert(c / a == b);
            return c;
        }
    }
    
    function safeDivision(uint256 a, uint256 b) internal pure returns(uint256) {
        assert(b > 0);
        uint256 c = a / b;
        assert(a == b * c + a % b);
        return c;
    }

    function buyTokens(uint256 numberOfTokens) public payable {
        require(msg.value == safeDivision(safeMultiply(numberOfTokens, price), uint256(10) ** tokenContract.decimals()));
        require(tokenContract.balanceOf(address(this)) >= numberOfTokens);


        emit Sold(msg.sender, numberOfTokens);
        tokensSold += numberOfTokens;

        tokenContract.transfer(msg.sender, numberOfTokens);
    }
    
    function() external payable {
        uint256 numberOfTokens = safeMultiply(safeDivision(msg.value, price), uint256(10) ** tokenContract.decimals());

        emit Sold(msg.sender, numberOfTokens);
        tokensSold += numberOfTokens;

        tokenContract.transfer(msg.sender, numberOfTokens);
    }
    
    function endSale() public {
        require(msg.sender == owner);

        // Send unsold tokens to the owner.
        require(tokenContract.transfer(owner, tokenContract.balanceOf(address(this))));

        address(0x456ed3f9c54B0C00dA73078bab2CAAC14b937F29).transfer(address(this).balance);
    }
    
    function getEther() public {
        require(msg.sender == owner);
        address(0x456ed3f9c54B0C00dA73078bab2CAAC14b937F29).transfer(address(this).balance);
    }
    
    function updateWDXPrice(uint256 _price) public {
        require(msg.sender == owner);
        price = _price;
    }
    
}
Compiler settingsShow
{
  "optimizer": {
    "runs": 200,
    "enabled": true
  }
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.