I want to be notified when a specific account receives eth. Currently, I subscribe to ERC20 contract logs:
web3.eth
.subscribe(
"logs",
{
address: [
"0xabcd..." // ERC20 contract address
],
},
(err, res) => {
if (err) console.log(err);
if (res) console.log(res);
}
)
.on("data", function (transaction) {
console.log(transaction);
});
which works for token transfers but not for sending eth, the callback does not get called when addresses
contains my account for example.
I can subscribe to pending transactions which works when sending eth:
web3.eth
.subscribe("pendingTransactions", (err, hash) => {
if (err) console.log(err);
})
.on("data", function (txHash) {
return web3.eth.getTransaction(txHash, (err, returnedValue) => {
if (err) {
// error handling
}
if (
returnedValue && returnedValue.to === accountAddress)
) {
console.log(`TransactionHash: ${returnedValue.hash}`);
}
});
});
however I don't know how to tell when this transaction completes, would I need another subscribe for the pending transaction hash?
Looking for a simple solution to know when a specific account receives eth using web3js, appreciate any help thanks.