3

I wanted to know where I can find the current pending transaction for an account which isnt committed. Is it even possible? How can I get transaction hashes for transactions which are pending? Any API for this purpose?

2 Answers 2

2

Well I know of one way that should work.

Use web3js or geth console and invoke whatever function/transaction. If you use the .sendTransaction() method it will return the transaction hash, which you will then use to look up your transaction status.

Next, using Etherscan API you can use the transaction endpoint:

https://etherscan.io/api?module=localchk&action=txexist&txhash=<<TX HASH>>

The response should look like this:

{"status":"1","message":"OK","result":"False"}

Next use the Etherscan transaction API. It will not tell you if it is pending, but if the transaction was a success/error it will return a different response:

https://api-rinkeby.etherscan.io/api?module=transaction&action=getstatus&txhash=<<TX HASH>>&apikey=<<API KEY>>

{"status":"1","message":"OK","result":{"isError":"0","errDescription":""}}

If isError is 0 then it was successful/ If isError is 1 then the transaction failed.

To sum it up, as long as you get the transaction hash from the .sendTransaction() (so you know it's a valid transaction), you can now hit the first endpoint with the ?action=txexists, which will return if the tx exists. Then you can hit the second endpoint to see if the TX passed or failed. So prior to you needing to hit the second endpoint, you will know the TX is pending since it does not exist yet.

If the above method is too confusing for you then below is how Etherscan.io currently gets pending transactions.

I pulled it from their website source code.

var interval;
var loopcounter = 1;

// startTxPendingCheck is a global window variable set by another script

if (startTxPendingCheck) {
    var div = document.getElementById('spinnerwait');
    div.style.display = 'block';
    interval = setTimeout(checkForConfirmedTx, 2000);
    function checkForConfirmedTx() {
        if (loopcounter < 45) {
            $.ajax({
                url: "/api?module=localchk&action=txexist&txhash=" + txHash,
                type: "GET",
                success: function(data) {
                    if (data.result == "True") {
                        window.location.href = "/tx/" + txHash;
                    }
                },
                dataType: "json"
            })
            loopcounter = loopcounter + 1;
            interval = setTimeout(checkForConfirmedTx, 20000);
        } else {
            stopInterval();
        }
    }
    function stopInterval() {
        console.log("stopInterval called");
        var div = document.getElementById('spinnerwait');
        div.style.display = 'none';
        clearTimeout(interval);
    }
    function startInterval() {
        console.log("startInterval called");
        clearTimeout(interval);
        var div = document.getElementById('spinnerwait');
        div.style.display = 'block';
        interval = setTimeout(checkForConfirmedTx, 5000);
    }
}
1

To find all your pending transaction go to https://etherscan.io/ and search for your account address. you will get there all the transactions with their statuts. Besides etherscan provides you an API to get all these details.

1
  • That API I think only shows the transactions which are committed no? Nov 1, 2017 at 12:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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