Post
Topic
Board Altcoin Discussion
Re: Receiving eth by contract and call fallback function
by
mvrcrypto
on 05/02/2018, 11:36:40 UTC
Yes, this is correct. Look at the ethereum crowdsale example https://ethereum.org/crowdsale

Code:
    /**
     * Fallback function
     *
     * The function without name is the default function that is called whenever anyone sends funds to a contract
     */
    function () payable {
        require(!crowdsaleClosed);
        uint amount = msg.value;
        balanceOf[msg.sender] += amount;
        amountRaised += amount;
        tokenReward.transfer(msg.sender, amount / price);
        FundTransfer(msg.sender, amount, true);
    }