Skip to content

Instantly share code, notes, and snippets.

@denniswon
Created December 12, 2019 08:44
Show Gist options
  • Save denniswon/07531526c63283188a47b9ee39ed7025 to your computer and use it in GitHub Desktop.
Save denniswon/07531526c63283188a47b9ee39ed7025 to your computer and use it in GitHub Desktop.
getAccountTransactions
function getAccountTransactions(accAddress, startBlockNumber, endBlockNumber) {
// You can do a NULL check for the start/end blockNumber
console.log("Searching for transactions to/from account \"" + accAddress + "\" within blocks " + startBlockNumber + " and " + endBlockNumber);
for (var i = startBlockNumber; i <= endBlockNumber; i++) {
var block = hmy.getBlockByNumbrt(i, true);
if (block != null && block.transactions != null) {
block.transactions.forEach( function(e) {
if (accAddress == "*" || accAddress == e.from || accAddress == e.to) {
console.log(" tx hash : " + e.hash + "\n"
+ " nonce : " + e.nonce + "\n"
+ " blockHash : " + e.blockHash + "\n"
+ " blockNumber : " + e.blockNumber + "\n"
+ " transactionIndex: " + e.transactionIndex + "\n"
+ " from : " + e.from + "\n"
+ " to : " + e.to + "\n"
+ " value : " + e.value + "\n"
+ " gasPrice : " + e.gasPrice + "\n"
+ " gas : " + e.gas + "\n"
+ " input : " + e.input);
}
})
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment