Skip to main content

Tracking deposits

After everything is ready, you can implement deposit tracking.

For that, iterate through all transactions in each block to search for payment_receiver_inc operation with an address matching the address in which you are interested:

async function trackDeposit(address: string) {
// some logic we want to execute on deposit
function onDeposit(deposit: any) {
console.log(deposit)
}
let latestBlock = (await networkStatus()).current_block_identifier.index
while (true) {
// check if transactions to the deposit address are present in the latest block
const txs = (await waitForBlock(latestBlock)).block.transactions
const deposits = []
for (let tx of txs) {
for (let op of tx.operations) {
if (op.account.address === address && op.type === "payment_receiver_inc") {
deposits.push({
tx_hash: tx.transaction_identifier.hash,
amount: op.amount.value,
})
}
}
}

// process deposits
for (let d of deposits) {
onDeposit(d)
}

latestBlock += 1
}
}