I'm trying to create a smart contract for a basic raffle system where the user deposits funds to the contract and then a user is picked and the winner is sent the ether from the contract, I've got everything working apart from invoking a request to the user to deposit Ether to the contract and am wondering how I would perform this.

In short, I'm trying to create a function whereby the user can enter a number of Ether that they to deposit and the contract will accept it.


1 Answer 1


See https://programtheblockchain.com/posts/2017/12/15/writing-a-contract-that-handles-ether/. In particular, you need the payable modifier on the function. For example:

function buyTicket() payable public {
    // In here, msg.value is the amount, in ether, that was sent
  • Thanks for that, was having trouble finding documentation on the subject
    – JAG
    Jan 23, 2018 at 0:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.