Submit transaction to multiple node providers at the same time?

Is there a way to submit transaction to multiple node providers at the same time?

For example I have moralis, infura, quicknode and alchemy endpoints and I want to submit same transaction to all of them at the same time… reason is, to make transaction included in next block fast as possible. If I rise gas price it doesnt help…

I am using ethersjs and nodejs.

you should build the raw transaction first, and then it should be easy to send it directly to different RPC nodes

I want to call contract method: Contract.myMethod(…

I tried like that:

let txPromiseAlchemy = Contract.myMethod(…
let txPromiseInfura = Contract.myMethod(…
let txPromiseQuick = Contract.myMethod(…

txPromiseAlchemy.then((tx) => {
log("Transaction hash: " + tx[‘hash’]);
});

txPromiseInfura.then((tx) => {
log("Transaction hash: " + tx[‘hash’]);
});

txPromiseQuick.then((tx) => {
log("Transaction hash: " + tx[‘hash’]);
});

But this fails if I get error for example “execution reverted” from one of the calls. Also transaction is not sent to all of the providers at the same time… Alchemy is always first?

this may not work for you, you have to get to the payload that is sent to the RPC node, and send it to multiple RPC nodes

it should be the same transaction hash for all of them

Can I ask you for quick example how to do that please?

I don’t have an example on hand now, as an idea you can build the transaction, get the transaction payload before it is sent to the RPC node and send same transaction payload to multiple RPC nodes

or build the transaction and use same nonce and gas price for all the rpc nodes, you will have to specify the transaction parameters somehow, this doesn’t work always well if you are making a lot of transactions as you will have to keep track of the nonce

yeah I have no clue how to do that, I am searching on google, but I can’t find anything about that :confused:

when I call Contract.myMethod(… promise returns me something like that:

{
type: 2,
chainId: 137,
nonce: 2909,
maxPriorityFeePerGas: BigNumber { _hex: ‘0x3356d2fd00’, _isBigNumber: true },
maxFeePerGas: BigNumber { _hex: ‘0x3356d2fd00’, _isBigNumber: true },
gasPrice: null,
gasLimit: BigNumber { _hex: ‘0x038e7c’, _isBigNumber: true },
to: ‘0xe957a6…’,
value: BigNumber { _hex: ‘0x00’, _isBigNumber: true },
data: ‘0xa1305b1…’,
accessList: [],
hash: ‘0xdfb8bfdeb884e8c38c235e…’,
v: 0,
r: ‘0x290727d51b24190fce9d04c…’,
s: ‘0x547d52ac59bf153886f60b8…’,
from: ‘0xbf1660…’,
confirmations: 0,
wait: [Function (anonymous)]
}

I dont know how to get payload or hash before it is send to RPC node?

check the methods, maybe it is a method to build a transaction payload from that data, it has all the required info in that output that you pasted

There is no such method on that contract…

not in the contract, in the library that you use to make that transaction

Yeah sorry, I am using ethersjs

maybe this helps

https://ethereum.stackexchange.com/questions/84561/building-a-raw-contract-transaction-with-ethers-js
The way you can use populateTransaction in Ether.js is:

const contract = new Contract(CONTRACT_ADDRESS, CONTRACT_ABI, Wallet);
const params = [value];
const action = 'myFunction';
const unsignedTx = await contract.populateTransaction[action](...params);
Then you can simply sign and send your transaction like:

await Wallet.sendTransaction(unsignedTx);
https://docs.etherscan.io/tutorials/signing-raw-transactions
// sign and serialize the transaction 
  let rawTransaction = await wallet.signTransaction(transaction).then(ethers.utils.serializeTransaction(transaction));
  
  // print the raw transaction hash
  console.log('Raw txhash string ' + rawTransaction);