Fast Polygon RPC endpoint

Hi,

Iā€™m working on an app for which it is crucial to make transactions confirmed on the Polygon chain as fast as possible.

Iā€™m watching my transactions on https://explorer.blocknative.com/, right now with the free Moralis endpoint I can get my transactions confirmed in 3-4 blocks.

Is there a way to speed up this process?

Thanks,
Tamas

what you mean by I can get my transactions confirmed in 3-4 blocks?

I use ethers, for testing purposes I send Matic between two of my addresses.

I log the actual block number, when I invoke wallet.sendTransaction.
Then I check the block number when my transaction is actually confirmed on the blockchain (on https://polygonscan.com or https://explorer.blocknative.com/).

Iā€™m building an arbitrage bot and this 3-4 blocks delay means that only 1 out of 10 transactions is confirmed, the others are failing.

ok, so you want your transactions to be confirmed faster, that could depend on the RPC node that is used, and also it could depend on the gas price when there are a lot of transactions waiting to be processed.

you can try different node providers, you could send the transaction to multiple nodes at the same time

1 Like

I tried almost all of the RPC endpoints listed here: https://docs.polygon.technology/docs/develop/network-details/network/#polygon-mainnet

Gas price should be fine, I use an API to make sure gas price is high.

I havenā€™t tried to send my transactions to multiple nodes at the same time, Iā€™ll give it a try.

Thanks for the tip.

Do you maybe have a code example how to send the same transaction to multiple nodes quickly?

I got a ā€œreplacement fee too lowā€ error, even though I increased the gasPrice.

where from you got that error, from your script or from the node?

Edit:
It looks like I made a mistake when I set up the wallets, feel free to ignore my original message, I think I got it working.


Itā€™s coming from the node.x
I found an article which suggests to increase the gas price at least 10%, which kinda solved the issue, I only get the ā€œreplacement fee too lowā€ from time to time.

However, sending the transaction to multiple nodes doesnā€™t seem to be helping. Testing ~10 times, always the last node is the ā€œwinnerā€ who confirmes the transaction, I assume this is because I increased the gas price.

I was under the impression that it should be random which node includes the transaction.
This way it still takes 2-3 blocks till my tx is confirmed, as it was before when I sent it to 1 node only.

Iā€™m attaching my code, let me know if you see something wrong here. I initialised the wallets with different endpoints - Alchemy, Moralis, QuickNode, Ankr.

const sendTxEthers = async () => {
  let nonce = await ethersProvider.getTransactionCount(MY_TEST_ADDRESS);
  
  let tx = {
    from: MY_TEST_ADDRESS,
    to: MY_ADDRESS,
    value: "0x01",
    nonce: nonce,
    maxPriorityFeePerGas: gasPrice,
    maxFeePerGas: (BigNumber.from(gasPrice).mul(2)).toHexString()
  }

  let txPromise = wallet.sendTransaction(tx);

  let txMoralis = getSpeedUpTx(tx);
  let txPromiseMoralis = walletMoralis.sendTransaction(txMoralis);


  let txQuick = getSpeedUpTx(txMoralis);
  let txPromiseQuick = walletQuick.sendTransaction(txQuick);


  let txAnkr = getSpeedUpTx(txQuick);
  let txPromiseAnkr = walletAnkr.sendTransaction(txAnkr);

  
  // Logging to check which node "won"

  txPromise.then((transaction) => {
    log("sendTxEthers transaction", transaction);
  });

  txPromiseMoralis.then((transaction) => {
    log("sendTxEthers transaction Moralis", transaction);
  });

  txPromiseQuick.then((transaction) => {
    log("sendTxEthers transaction Quick", transaction);
  });

  txPromiseAnkr.then((transaction) => {
    log("sendTxEthers transaction Ankr", transaction);
  });  
}

// Multiple gas by 1.2
const getSpeedUpTx = (tx) => {
  let txCopy = JSON.parse(JSON.stringify(tx));

  txCopy.maxPriorityFeePerGas = BigNumber.from(txCopy.maxPriorityFeePerGas).mul(12).div(10).toHexString();
  txCopy.maxFeePerGas = BigNumber.from(txCopy.maxFeePerGas).mul(12).div(10).toHexString();

  return txCopy;
}

Thanks @cryptokid for the help, it was very useful for me.

It looks like you are sending different transactions to different nodes, and every time replacing the previous transaction. I think that you can send it without changing the transaction gas price and if the node gives that error then it means that the node already knew about that transaction.

what is the reason of that 3-4 block of delay? like if you use 10x gas you get same delay? like it is because there are too many transactions to get processed or is because the transaction is sent with a delay somehow?

I think youā€™re right, earlier I made a mistake setting up the endpoints.

Now I send the same transaction to ~7 endpoints and different nodes confirm the tx, mostly in 2 blocks.
Also transactionIndex is usually 0, so it looks like I have the first spot in the block.
I donā€™t know why I cannot make it to the next block, but this is still the best result I have so far.

Increasing the gas price doesnā€™t do much anymore, I use this URL to get the current gas price and even if I multiple it by 10 I get the same results.

Iā€™m using blocknativeā€™s mempool explorer, where I can see that ā€œblocksPendingā€ is usually 2.
I donā€™t really know any other way to track the mempool. Not sure how I could monitor whatā€™s happening after I send the tx.

if transaction index is 0 then it could mean that you donā€™t have to increase the gas price more

blocksPending 2 maybe it means that a one block is already in processing and you can only add in the second block your transaction

1 Like

Hello moltam89, can you share code, how you submit transaction to multiple node providers at the same time? I would appreciate it <3