getTransactionCount always return null or zero value

I’m sending raw Transactions message to Ropsten network via Infura, however, I always get back the nonce null value as result. I’m puzzled. Can anyone please help out?
This is my account address 0xd61794624e9542495A72Cfac7Cc10B4275b8f8E5.
Is there any ways I can debug and troubleshoot the issue by myself on Infura?
Thank you.
Best,
David

Hi David, can you share the sample code you are using that generates this behavior?

1 Like

Thank you for replying my message @wuehler.
KIndly, see the code below.

sendERCTokenWithRawTransaction(){
          
          var count = web3.eth.getTransactionCount(fromAddress ,function(error, nonce) {
          if(!error){
          var data = _myContract.transfer.getData(toAddress, web3.toHex(567),{from:fromAddress});
          var gasPrice = 10;
          var gasLimit = 548020;
          const chain_id =3;
          const gas = 548020;
          var rawTransaction = {
            "from": fromAddress,
            "nonce": web3.toHex(nonce),
            "gasPrice": web3.toHex(gasPrice),
            "gasLimit": web3.toHex(gasLimit),
            "to": address, // "To:" -> ERC20 contract's address instead of the receipient.
            "value":web3.toHex(web3.toWei("0.000", "ether")),
            "data": data
          };
      
            var privKey = Buffer.from('private', 'hex');
            var tx = new Tx(rawTransaction,{ chain: 'ropsten' });
      
            tx.sign(privKey);
            var serializedTx = tx.serialize();
           console.log('RawTransaction :' + '0x' + serializedTx.toString('hex'))
           console.log('nonce:'+nonce)
           web3.eth.sendRawTransaction('0x' + serializedTx.toString('hex'), function(err, hash) {
            if (!err)
                console.log(hash);
            else
                console.log(err);
          });
          }
        })
      }

Could it be due to the earlier pending transaction 0xe090b15c18a10dc90880adff8c4c56d1c1406cb9cb39fe7a57e9c2b237228aa2

I have been monitoring this transaction for more than 5 minutes, it still shows as pending status. Why is that?
It there anything have gone wrong in my code?
Kindly, advise.

It certainly could be due to the fact that the transaction hasn’t been accepted by a miner and added to the chain. You could try manually sending a transaction with a higher nonce and more gas to get that to clear.

As an aside, we are working on an API to give visibility into the pending txn pool which would help you to programmatically manage this situation.

Thank you for your advice. @wuehler.
I will try to set higher nonce and higher gas to clear the transaction, but, problem is I’m not sure whether my transaction is valid and why is that taking so much time to be mined. Please advise again, sir.

Typically, when a txn doesn’t get mined, that is due to the gas price being too low. I notice you set a gas price of 10 wei, perhaps retry setting the gas to 20 wei (or more)?

You could also test the code against another test network like Görli to see if you can see any different behavior.

Noted with thanks, @wuehler.

@wuehler- A quick question here again, what will happen to those pending transactions? Will they be mined eventually?

Correct, theoretically the txn in the pending txn pool will eventually be picked up and executed, and if successful added to a block. I have seen my own txns take hours but finally processed.

If you resend the txn with a higher nonce, the original txn will be dropped.

Once again, many thanks

Hi @wuehler- It seems the pending transaction still stuck at the pending status. Wondering what has gone wrong here, I already pushed a new transaction to Ropsten network with higher gas value and higher nonce. Still no luck! Would really appreciate if you could give me some hints.
Thank you.

Transaction hash id : 0xe090b15c18a10dc90880adff8c4c56d1c1406cb9cb39fe7a57e9c2b237228aa2

Can you try sending another txn with the same nonce as that first one that is pending (185) with the higher gas limit?

Sure, let me try that and I will keep you posted.

It looks like you are making progress. I see your txn with nonce 185 was successful about 6 hrs ago, however then you attempted sending new txns with higher nonces again. From here, I suggest one at a time, sending a new txn with first 186, then 187, then 189. That should clear all of the old txns that are pending.

Thank you @wuehler. Yes, It went through once, but the subsequence transactions are still pending. I’m wondering why.

your gasPrice is just too low!
For 10 or 100 wei, barely no nodes will bother with your transactions. You need to set gasPrice close to 1 Gwei = 1.000.000.000 wei