I'am using truffle 4.

Suppose I have the following js code:

let instance = await Values.deployed()                                                                              
let result = await instance.addValue(hash)

Now imagine that something fails in my computer (for instance: somebody pulls the plug) while awaiting for the addValue result.

How can I recover the receipt of that transaction?

  • Inside the addValue function, emit an event which contains the value which is about to be returned, and then you can always search for it in the blockchain, regardless of the state of the machine which has issued this call. Jul 19 '18 at 19:29
  • Is there a way in truffle to search the blockchain? Or should I use web3 directly?
    – andrés
    Jul 20 '18 at 0:00

One solution is to generate events when addValue() is completed successfully. Then when an event processed you store the last event in a database1.

If your server crashes, or the connection is down, you can retrieve from the database the last processed event and proceed from there.

1 You do not need to use a database, you can store the last event in a txt file, or if you are in the browser in the document storage.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.