I'm trying to create two transactions with the same nonce and send those transactions to two different nodes. Such as:
const Web3 = require('web3');
const web3_1 = new Web3(rpcURL1); // node 1
const web3_2 = new Web3(rpcURL2); // node 2
const web3_3 = new Web3(rpcURL3); // node 3
// Let's call tx1
web3_2.eth.sendTransaction(
{
from: account0, to: account1, value: web3_1.utils.toWei("1", "ether"), nonce: 3
}
);
// Let's call tx2
web3_3.eth.sendTransaction(
{
from: account0, to: account1, value: web3_1.utils.toWei("1", "ether"), nonce: 3
}
);
I'm testing this on a private network with 3 nodes. All the nodes have each other as peers.
The error I'm getting when I run the code above: Error: Returned error: known transaction: [txHash]
According to web3.js
documentation, sendTransaction
method returns a callback. Since I'm not waiting for this callback to be resolved, I assume transactions would be fired simultaneously or at very close times.
My guess is that since I'm using a private network and there are only three nodes, transaction propagation between the nodes is pretty fast (my assumption might be wrong). That's why, even though the transactions are submitted at very close times, tx1
is propagated to node3
before tx2
reaches node3
. I believe that would be the only way for node3
to know about tx1.
If you think that's the case, is there any way in Ethereum to control the transaction propagation process or slow down it?
If you think that's not the case, what would be your suggestion for me to create these double-spending transactions on different nodes?