0

I want my front end to show the status of my solidity functions. When my functions are successful I fire a "success" event. I can watch for that event and respond to it like so:

const events = myContract.allEvents({ fromBlock: 0, toBlock: 'latest' })
      events.watch( (err, evt) => {}

However, I would also like to display when these functions are pending and when they have failed, but I cant figure out how.

I notice that when I do this:

await web3.eth.filter("pending").watch(
      function(error,result){
          if (!error) {
              console.log("pending" + result);
          }
      }
    ) 

I can see various transactions as they are pending, but I'm not sure how to tell if one of them corresponds to one of the functions I care about.

I'm not even sure how I would figure out if a transaction has failed.

Any help would be great thanks!

3

I can see various transactions as they are pending, but I'm not sure how to tell if one of them corresponds to one of the functions I care about.

After you make a transaction, web3 gives you a transaction hash. This uniquely identifies the transaction.

I'm not even sure how I would figure out if a transaction has failed.

You use eth.getTransactionReceipt(transactionHash) (after transaction is mined) and check the status field. A status of 1 denotes success, whereas 0 denotes failure.

  • The problem is that if I refresh the page then I lose the transaction hash web3 gives me. Is there a way to identify which transactions are which function without the transaction hash? Perhaps by using the method signature? – mark oland Feb 11 '18 at 3:09
  • @markoland localStorage not an option? – ReyHaynes Feb 11 '18 at 3:13
  • @ReyHaynes hot really. were trying to build without dynamic hosting – mark oland Feb 11 '18 at 3:14
  • @markoland Gotcha. Well, I only mentioned it because you are always going to lose data if you refresh the page without actually storing it somewhere. – ReyHaynes Feb 11 '18 at 3:23
  • I guess it will be possible to regenerate the transaction hash from the transaction fields: to, nonce, gasPrice, data, gasLimit and value, but this means you will have to retain these values instead. – lunr Feb 11 '18 at 3:34

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.