Title: Receiving eth by contract and call fallback function Post by: myapple on February 05, 2018, 10:25:30 AM I am thinking to create a contract to receive ethers
Once ether is received the contract will automatically call a fallback function In this fallback function it will calculate the coins based on msg.value and send the tokens back to the sender address msg.sender In this way once my contract received ethers it will automatically send back tokens according to a fixed exchange rate Is this correct?thanks Title: Re: Receiving eth by contract and call fallback function Post by: mvrcrypto on February 05, 2018, 11:36:40 AM Yes, this is correct. Look at the ethereum crowdsale example https://ethereum.org/crowdsale (https://ethereum.org/crowdsale)
Code: /** Title: Re: Receiving eth by contract and call fallback function Post by: falconfree on February 05, 2018, 11:38:37 AM I am thinking to create a contract to receive ethers HelloOnce ether is received the contract will automatically call a fallback function In this fallback function it will calculate the coins based on msg.value and send the tokens back to the sender address msg.sender In this way once my contract received ethers it will automatically send back tokens according to a fixed exchange rate Is this correct?thanks It's correct way. Have you send external tokens (tokens whitch are existing) from our contract? If it is true, then see ethereum Crowdsale contract (on official web site) - payable function with transfer function. |