Let's say I have a contract with a "withdraw" function. Now someone calls this withdraw function, resulting in the contract doing something like receiverAddress.transfer(amount).

Now I would like to keep a list of all outgoing transactions in the contract. I understand the outgoing transaction is actually just a part of the calling transaction, so there is not yet a transactionID to store in the contract. Correct?

What options does my contract have if i want to keep a list of all performed transactions? I was envisioning a list of transactionIDs, but as far as I understand this is not possible.

  • Just keep whatever data you need... If you care about the block number, save that, if you care about the value save that, etc.... – Tjaden Hess Mar 24 '17 at 20:14
  • Fair enough, but what i really want to have is a function of the contract that lists all performed withdrawals with their transactionIDs. – TripleSpeeder Mar 24 '17 at 21:59
  • 1
    You can't get the transaction IDs, because they rely on the result of the transaction. What you can do is just issue an event, and then it would be pretty easy for an offchain client to compile that list – Tjaden Hess Mar 24 '17 at 22:01
  • Instead of transfer which will throw the calling contract if the transfer fails, use call which returns a success bool. You can store your transaction details prior to calling (and perhaps delete if it fails) e.g. if(!tx.to.call.value(tx.value)(tx.data)) {delete tx;} – o0ragman0o Mar 25 '17 at 1:58
  • @TjadenHess, event usage sounds interesting. I'm still lacking full understanding of Events, but I assume the client/dapp will be able to see all past events and not just the "live" ones? – TripleSpeeder Mar 26 '17 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.