I want to watch a set of Ethereum contracts and be notified (preferably by email) when a contact receives a payment to it.

I prefer me not to write my own software for this and not to install it on my own server, but programming suggestions are welcome.

  • are those your own contracts or just any contracts you want to watch ? – Cԃաԃ Dec 21 '18 at 6:02
  • @Cԃաԃ I created these smart contract myself, using my own software – porton Dec 21 '18 at 6:08
  • I wrote an answer for a setup you could use, I'm currently running this setup myself. – Cԃաԃ Dec 21 '18 at 6:26

You could use the next setup.

1) in solidity inside of the payable function add event that will fire every time someone pays. for example : PaymentReceived

event PaymentReceived(address from, uint amount);
emit PaymentReceived(msg.sender, msg.value);

2) start a nodejs server with web3js and watch for the event PaymentReceived with web3js it will be something like this :

var ev = myContract.PaymentReceived({},{fromBlock:0, toBlock:'latest'});
ev.watch(function(error, result){
                // send email here


3) you could use module like shelljs to run a script on linux to send email.


P.S. when watching for the event, you may want to use some sort of mechanism to check if you already send the notification email for a payment. Since every time you restart node application it will trigger send email script for every emit from solidity (because of this : {fromBlock:0, toBlock:'latest'}) I would save it a database, say mysql with tx as unique key, and send email only if it hasn't been send already.

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.