# Listening for Deposits and Transaction Confirmations Web3js

I'm building a webapp using nodejs and web3js. I have a simple use-case: I provide the user with an address to which he should deposit funds. I want to then listen on my nodejs server for:

1. when the user deposits funds to this address
2. the transaction which deposits these funds has gone through 12 confirmations.

I know I can check the balance of the account using:

var balanceWei = web3.eth.getBalance(walletAddress).toNumber();


however this is not enough in my use case. I need to know when a transaction occurs which deposits funds into this account, as well as when this transaction is confirmed so that I can make these funds available to the user within my app.

There are several solutions to this:

1. You can search in every new block that arrives for transactions related to your account as described in this answer (an script is given).

2. You can use etherscan API, which will give you all the transaction to and from a particular account starting at a block number given. This is described here

In ethersacn you will do a request, for instance:

where you specify the address, startblock and endblock interval in which to look for your transactions.

1. Write a smart contract and give your users the address of the contract instead, then you can add events on it about the transactions. In this way, you can use filters in web3 to get the information of any new deposit to your contract account. An example of such contract is:

contract MyContractAccount{

constructor(){
owner = msg.sender;
}

function () payable public{