Smart Contract that executes something when the contract address receives ether.

Hey guys,

Just want to start off by saying I'm not a professional programmer. I'm a complete hobbyist, but I've been messing around on the Rinkeby test net writing and compiling very simple smart contracts cause I thought it'd be fun.

I am currently just executing my smart contract's functions through the Ethereum wallet app via the contract's admin page. I was wondering if it is possible to make a smart contract that executes a function when it receives a regular ether transaction to it, and not by the function calls through the wallet app.

So you get what I'm talking about, here's an extremely simple and pointless example:

Every time the address received a transaction of ether from anyone sending to it, it would automatically increase a "deposits" variable by 1, without the sender or admin having to tell it to do that.

Is something like that possible?

Thanks,

Joe

Comments

  • EtherGeekEtherGeek Member Posts: 34
    Yes, definetly is, but I don't quite know how it would be done. I think you could write that in your wallet UI possibly, would love to see the code, of course gas will be consumed by such an operation. I would like to write a small one say at each 3 receptions the contract would send back all ether received to the sender, just to see, would be curious.
  • joriglierijoriglieri Member Posts: 2
    Thanks for the reply!

    So, what you're saying is that I'd need to write that functionality into the actual wallet client and not the smart contract itself?

    Thanks,

    Joe
  • EtherGeekEtherGeek Member Posts: 34
    No no, the code definetly has go in the smart contract. The wallet you are using is just a user interface to allow you to do that. After further review, it is my understanding that each time a transaction is sent to your contract it's code will be executed. Keep us posted on your trials.
Sign In or Register to comment.