1

I have been trying to send a tx using nodejs for some time now, however the tx only output’s the transaction hash but it is never confirmed or mined, I am using the following params for the same

{
  txParams: {
    nonce: '0x24b',
    from: '0x2FF312a35e4bBD2158997D90CC81bC298059F2D1',
    gas: '0xac7b',
    gasPrice: '0x12a05f200',
    gasLimit: '0x4c4b40',
    to: '0xb7F1A82f326751E1F8387b4C54778836BfcEF9b8',
    data: '0x289f0fee0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000607b2234383037223a5b343830372c22434f4d504c45544544222c22307834326137653836376133303261396530643732643735623539383836353933373062376366356131343532613336653035656166623130666433383963343235225d7d'
  }
}

Please let me know if more information is required. Here are some txs for reference

1 Answer 1

0

Assuming your address is indeed : 0x2FF312a35e4bBD2158997D90CC81bC298059F2D1

You might have unintentionally created a nonce gap (see this answer).

That account has a nonce of 556 (1 + last tx nonce) but in your code you are setting your nonce to 0x24b which is 587. That's a nonce gap. Transactions will not be processed out of order, so it's pending until the gap is filled.

This is also checked with web3 against your account :

import Web3 from "web3";

const web3 = new Web3(
  "https://speedy-nodes-nyc.moralis.io/YOUR-MORALIS-ID/polygon/mumbai"
);

const count = await web3.eth.getTransactionCount(
  "0x2FF312a35e4bBD2158997D90CC81bC298059F2D1"
);

console.log(`Next tx nonce should be : ${count}`);
// prints : 556

Try like this :

  txParams: {
    nonce: '0x22c', // 556
    from: '0x2FF312a35e4bBD2158997D90CC81bC298059F2D1',
    gas: '0xac7b',
    gasPrice: '0x12a05f200',
    gasLimit: '0x4c4b40',
    to: '0xb7F1A82f326751E1F8387b4C54778836BfcEF9b8',
    data: '0x289f0fee0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000607b2234383037223a5b343830372c22434f4d504c45544544222c22307834326137653836376133303261396530643732643735623539383836353933373062376366356131343532613336653035656166623130666433383963343235225d7d'
  }

You should let web3 / ethers or whatever you are using set the tx nonce for you depending on your account. Removing the nonce entry in your object is enough to let web3 know that it has to fill it for you.

Or fill it manually, for example using Web3 getTransactionCount. But don't set it to a fixed value as by definition it can only work when the tx nonce matches the expected nonce which can only happen once.

If that is indeed the issue, you might also want to cancel your previous tx. But you are on a testnet so I doubt it's very important anyway.

2
  • Thanks for the reply hroussille. I was using the getTranactionCount and using the 'pending' arg for the nonce, however none of the TXs were being mined, so I thought it might be due to low gas fees, so I started using static nonces so that they can be replaced with high gas fees, but no luck, I will definitely try your approach and check if the nonces are in order or not, and if it doesn't work, I can always use a new account for the same.
    – hacker
    Dec 6, 2021 at 4:41
  • Yes, works like a charm, I switched to a new address and it works smoothly. Thanks a lot for the solution.
    – hacker
    Dec 6, 2021 at 10:26

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.