Skip to main content
replaced http://ethereum.stackexchange.com/ with https://ethereum.stackexchange.com/
Source Link

You must lookup all transactions made by an account and retrieveretrieve the transaction for the nonce you're interested in:

You must lookup all transactions made by an account and retrieve the transaction for the nonce you're interested in:

You must lookup all transactions made by an account and retrieve the transaction for the nonce you're interested in:

Source Link
Sebi
  • 5.3k
  • 6
  • 28
  • 52

You must lookup all transactions made by an account and retrieve the transaction for the nonce you're interested in:

function getTransactionsByAccount(myaccount, startBlockNumber, endBlockNumber, nonce) {
  if (endBlockNumber == null) {
    endBlockNumber = eth.blockNumber;
    console.log("Using endBlockNumber: " + endBlockNumber);
  }
  if (startBlockNumber == null) {
    startBlockNumber = endBlockNumber - 1000;
    console.log("Using startBlockNumber: " + startBlockNumber);
  }
  console.log("Searching for transactions to/from account \"" + myaccount + "\" within blocks "  + startBlockNumber + " and " + endBlockNumber);

  for (var i = startBlockNumber; i <= endBlockNumber; i++) {
    if (i % 1000 == 0) {
      console.log("Searching block " + i);
    }
    var block = eth.getBlock(i, true);
    if (block != null && block.transactions != null) {
      block.transactions.forEach( function(e) {
        if (myaccount == e.from && nonce == e.transactionIndex) {
          // Do something with the trasaction
          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"
            + "   time            : " + block.timestamp + " " + new Date(block.timestamp * 1000).toGMTString() + "\n"
            + "   gasPrice        : " + e.gasPrice + "\n"
            + "   gas             : " + e.gas + "\n"
            + "   input           : " + e.input);
        }
      })
    }
  }
}