I'm trying to send transactions to the polygon network using ethers.js. After submitting the transaction, i await tx.wait()
, but it fails to resolve 50% of the time. I saw other people were having similar issues but was due to their gas price being too low. I currently have this code:
const getWallet = (): Wallet => {
return new ethers.Wallet(PRIVATE_KEY, HTTP_PROVIDER);
};
const wallet = getWallet();
const gasPrice = 50000000000;
const swap1 = await wallet.sendTransaction({
data: tx1.data,
chainId: tx1.chainId,
from: tx1.from,
gasLimit: 350449,
gasPrice: gasPrice,
value: '0x' + new BigNumber(tx1.value).toString(16),
to: tx1.to,
nonce: nonce,
});
I've always returned an object that has the tx hash, but when I go to look up that hash on polyscan it never appears. After waiting sometimes up to an hour tx.wait() still does not resolve and the transaction still doesn't appear in polyscan.
I cancel my script, bump the gasPrice up by 20% and try to run it again w/ the same nonce (hoping to replace it). At that point I'm usually told the replacement gas fee is too low.
Can someone explain what I'm doing wrong here?