4

I am developing an app and I use JavaScript. I need to watch transaction from user browser. I use eztz method eztz.contract.send for create transaction. I receive back the transaction hash, but not return block id. Is there a reliable way to know the transaction status of this tx hash so that I know if my transaction was accepted by the network?

In this specific instance I am using alphanet and the ophash returned by eztz is ooTC8mMZ7dG1ReCXLPiTAN3qEUB7uNFuh9R8KZXEFbZZiZcypBf.

  • 2
    Possible duplicate of How can I understand why a transaction has failed? – Ezy Feb 6 at 14:28
  • I do not have a block, because eztz itself causes a block to be received inside the call operation – Михаил Магомедов Feb 6 at 14:28
  • sorry what do you mean that eztz "causes a block to be received inside the call operation" ? Please can you provide more details/infos about what you are doing and what is the status of the transaction so we understand clearly the context. Thank you! – Ezy Feb 6 at 14:29
  • Could it be that the block id(eztz.rpc.getHead()) will change if I receive it after calling the eztz.contract.send method? – Михаил Магомедов Feb 6 at 14:32
  • it does not make sense to me what you are saying. Can you paste here the message that eztz returns you ? it will be simpler that way. Can you find the transaction in TzScan ? – Ezy Feb 6 at 14:34
2

There's actually a new function with eztz that does this now:

eztz.rpc.awaitOperation(
  opHash, //The operation hash to watch
  interval, //Optional - Time between checks, defaults to 30 seconds
  timeout//Optional - Timeout - will end after this, defaults to 180 seconds
).then(function(blockHash){
  //Will resolve with the blockHash if found
  console.log("Found in block " + blockHash)
}).catch(function(){
  //Reject on time out
};

Using the defaults seem to work fine for me (waits approx 3 blocks).

0

I think you could send a raw rpc call using eztz:

eztz.node.query("/chains/main/blocks/head/operations").then(function(res){
  console.log(res);
}).catch(function(e){});

/chains/main/blocks/head/operations Gives you a list of operations included in the latest block also known as head. You can find a detailed explanation of this RPC endpoint here.

So the full solution could be, that you 'poll' this endpoint in a setInterval cycle, until you find a receipt for your operation, within a certain time frame.

E.g. in the next 1 minute, call the RPC endpoint, and if a receipt matching my operation id is found, we can conclude that the operation was included successfully.

Alternative tezos-client command would be:

tezos-client wait for <operation hash> to be included
  • I believe this solution is not robust in general because you are not guaranteed that the operation will be in the latest block. It could be in a subsequent block and because the full node does not have the transaction index you may find yourself unable to actually get the proper info that way. I believe OP should either build his own tx database or rely on an existing one like TzScan or Conseil. – Ezy Feb 6 at 15:43
  • I'm not sure how exactly has tezos-client implemented this, but using tzscan's api is one way. But i think if you start polling, before using eztz to inject an operation, you will certainly catch the block where the operation will be included, unless the baking time is too quick, or your fees are low and the operation simply won't be included anytime soon - which i don't think really happens. – Matej maht0rz Šima Feb 6 at 15:49
  • 1
    Tezos client blocks until it has the operation accepted or times out. You do not want the app OP is writing blocking and polling at quick interval is not a robust way. Ideally you would like to receive a notification that the tx was accepted but eztz does not support that i believe. So either you need to ask an index on a slower frequency or you need to use a local node which is not good if you want to do a mobile app – Ezy Feb 6 at 15:53
  • 1
    Depends on what the author wants to achieve, if he's looking to get new storage values for the contract after an entry point was executed - eztz provides a method to watch the contract's storage as well. – Matej maht0rz Šima Feb 6 at 15:58
  • 1
    Easy thanks! "Also calling eztz.contract.send, results into a POST call to this rpc endpoint. In my understanding, using raw RPC, your best bet is to look at the upcoming blocks / new heads, to look for your operation id" it is good answer. I will request a checking unit and if there isn’t there, I’ll watch the previous blocks! – Михаил Магомедов Feb 7 at 8:29
-1

So your transaction was posted in alphanet. If you search for operation ooTC8mMZ7dG1ReCXLPiTAN3qEUB7uNFuh9R8KZXEFbZZiZcypBf in TzScan (under alphanet) it is displayed here

With the transaction hash and block hash BMWZp5qBho1V62bb9necMuSuEaV5vm1G4Zu7mEQ7y8eaATHAfuB which contains your transaction you can follow the steps here to get the details about the outcome

I would recommend following the steps indicated in this other answer to get the details you want.

If you want to do things from code you should be able to call into the TzScan API through

https://api6.tzscan.io/v3/operation/oogKXTkRmJLBmnBQgP2My4QKRHAGLez96krSFshhg51hA8GEMVp

However it seems that this call does not work for the alphanet. I asked in this question if that's something to be expected, but for mainnet it should be ok.

[EDIT] Actually the answer to the other question is that you just need to use a different server for the query in alphanet. With your ophash you can get the block info with this command

https://api.alphanet.tzscan.io/v3/operation/ooTC8mMZ7dG1ReCXLPiTAN3qEUB7uNFuh9R8KZXEFbZZiZcypBf

  • I do not have a block, because eztz itself causes a block to be received inside the call operation :( – Михаил Магомедов Feb 6 at 14:27
  • I added step-by-step details now. you should be good now i think! – Ezy Feb 6 at 14:51
  • 1
    Sorry, but this answer is not suitable for eztz, because for these operations you need to know the id of the block, and eztz doesn’t return block id after send operation – Михаил Магомедов Feb 6 at 14:56
  • you have the id of the block in tzscan like i showed you. The node does not maintain an index of transactions so you cannot do a query (txhash=>block id) in the client node, you need to have an transaction database and tzscan does that for you (or conseil as well). hope this clarifies – Ezy Feb 6 at 14:57
  • 1
    you can send https query to tzscan to get the block id – Ezy Feb 6 at 14:59

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.