Example: I am making a shop where you can buy some digital items. Invoice with new ETH account is generated for every order. When customer pays invoice, order must be marked as completed. To do so I need some kind of notification (like wallet notify in bitcoin) when transaction is received.

I don't want to use any 3rd party service for notification. Application is for learning purposes.

What is the best solution for balance change notification?

Is checking every block for transactions to that account is still best approach?

Maybe Smart Contracts could bring some light?

Please advise.

1 Answer 1


You can use events for this. There is also no need to make each invoice an extra contract. You could use structs for this. It's cheaper and it has the advantage that you only have to watch for events of a single contract instance.


contract InvoiceManager {
    struct INVOICE {
        bool valid;

    mapping (uint => INVOICE) invoices;

    event InvoiceCreated(uint id, ...);
    event InvoicePaid(uint id, ...)

    function createInvoice(uint id, uint sum, ...) {
        INVOICE storage invoice = invoices[id];
        emit InvoiceCreated(invoice, ...)

    function payInvoice(uint id) public payable {
        ... process payment ...
        emit InvoicePaid(id, ...)

Now you can watch in your app for the events on this contract (see web3 documentation for this).

  • Sounds exactly what I was looking for. I will try to implement this. Thank you!
    – minus1
    Commented Mar 26, 2018 at 8:14
  • Trying to make it work, but can't understand if this approach is generating new address for every invoice if it does how does it work?
    – minus1
    Commented Mar 26, 2018 at 14:39
  • It‘s expecting an id from outside. You can easily generate a unique guid yourself.
    – ivicaa
    Commented Mar 26, 2018 at 14:47
  • Alternatively you can change the mapping to an array and push a new element to the array if you want to create a new one. Via events you can check what the new id is. Since arrays are mappings under the hood, you can leave gaps in the array after deleting invoices after a payment (if you want to).
    – ivicaa
    Commented Mar 26, 2018 at 14:51

Your Answer

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

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