0

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.

Thanks

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
1
  • Thanks for that, was having trouble finding documentation on the subject – JAG Jan 23 '18 at 0:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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