Ethereum Transactions – How to Get the Status of a Transaction in Go Ethereum

go-ethereum

Looking for a way to understand success (or failure) for ethereum transaction.

When we execute a contract method (send transaction) we receive it hash. Transaction is added to the block, block is added into chain and waiting for to be mind. It should be mined on one node and on others, success of failure would be clear after consensus stage.

The question is what is the proper way to wait for status of the transaction.

Here is a research on this topic

Polling
How can a DApp detect a fork or chain reorganization using web3.js or additional libraries?

External lib
https://github.com/barkthins/ether-pudding/blob/master/index.js#L375

Consensus
What number of confirmations is considered secure in Ethereum?
(why they define 12 as a result of secure transaction? It should 51% of all nodes, isn't it?)

Usage of filter and why it is not right way to go
What's the proper way to wait for a transaction to be mined and get the results?
Waiting for a transaction to be confirmed

Best Answer

Made a npm module called await-transaction-mined for this specific problem.

const awaitTransactionMined = require ('await-transaction-mined');
(async function() {
   var txHash = '0x6ee5d58c314d183f3ca70e2292b39dca5ae46141fe4e6b1da5b106dd506e589a';
   const minedTxReceipt = await awaitTransactionMined.await(web3, txHash);
})();

It polls the blockchain every 500ms to check if the transaction has been mined. Once mined it returns the transaction receipt.

Related Topic