Skip to content

Instantly share code, notes, and snippets.

@0xAnon101
Last active July 13, 2022 04:04
Show Gist options
  • Select an option

  • Save 0xAnon101/080020fcccae8eb3336d1261d3b2355b to your computer and use it in GitHub Desktop.

Select an option

Save 0xAnon101/080020fcccae8eb3336d1261d3b2355b to your computer and use it in GitHub Desktop.
subscribe function
subscribe(topic) {
this.web3.on(topic, async (txnHash) => {
setTimeout(async () => {
try {
const txn = await this.web3.getTransaction(txnHash);
if (txn !== null && txn.to !== null) {
if (this.accounts === txn.from.toLowerCase()) {
// dumps the data onto the CLI
console.log({
address: txn.from,
value: ethers.utils.formatEther(txn.value),
timestamp: new Date(),
txnHash: txn.hash,
});
}
}
} catch (err) {
console.error(err);
}
}, 60000);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment