1

I am working on private test net. Can I get the latest transaction address inside my contract. At the basic level I am trying to have a function getLatestTransaction() which will return me the latest transaction address.

At advanced level I want to have an array containing address of all the transactions.

eth
  • 85,679
  • 53
  • 285
  • 406
Prashant Prabhakar Singh
  • 8,026
  • 5
  • 40
  • 79

1 Answers1

2

No, you cannot get any transaction hashes from inside a contract.

You need a function in your contract to accept transaction hashes, feed them in, and can then store them in an array. But this will cost a lot of gas to keep updated, so isn't recommended.

Related question: Is it possible to get the transaction hash from within a Solidity function call?

eth
  • 85,679
  • 53
  • 285
  • 406
  • so basically there is no way I can have a function getLatestTransaction() that will return latest transaction hash?? – Prashant Prabhakar Singh Jul 26 '16 at 13:11
  • Not currently. The EVM doesn't provide the transaction hash, or data such as the nonce, so a contract cannot compute the hash on its own. – eth Jul 26 '16 at 13:22
  • But the geth console is able to display the transaction hash so they must be getting it from somewhere. If EVM doesn't provide transaction hash how is geth able to display it? – Prashant Prabhakar Singh Jul 26 '16 at 13:24
  • Geth gets the transaction so it can hash it; Geth has an EVM (the EVM does not have Geth). – eth Jul 26 '16 at 13:43
  • So how even can I have a function that accepts transaction hashes and later store them in array? I mean how that function will get Transaction hash as parameter? – Prashant Prabhakar Singh Jul 26 '16 at 13:56
  • One way is use Geth and do something like contract.putTransaction(transactionHash) where putTransaction is the function in your contract that accepts a transaction hash. – eth Jul 26 '16 at 14:01