0

I am trying to send a transaction to a contract through web3, with the following code:

const c = new web3.eth.Contract(contractData.abi, address)
console.log(new Date())
const x = await c.methods.drain().send(
      {'from': '0xxxxx', 'gasPrice': 5000000000}
)

Right before I send the transaction, I log in my console the current timestamp. When I check the transaction's timestamp through Etherscan, I usually get 5 secs more, meaning that the transaction takes 5 seconds to send.

How can I increase the execution speed? Will sending the request through RPC instead of Web3 help? Does it have to do with my node (unlikely, as I have 300 peers on a 32gb ram 16 core 720nvme server)? Will sending the transaction to multiple nodes help in increasing the speed at which the transaction is spread through nodes? Thanks for the help!

3
  • I use web3js and my tx are picked up by other nodes in a matter of milliseconds. I don't think that web3 is the problem. Maybe it's just etherscan that is slow in showing the tx on the website. – Undead8 Apr 8 at 2:27
  • @undead8 I am not referring to etherscan showing the transaxtion, I am referring to the transaction’s time stamp shows on etherscan, which I suppose is somewhat globally linked to the transaction itself and not to etherscan. This is why the 5 seconds discrepancy leads me into believing that web3 or transaction propagation is the problem – Riccardo Perego Apr 8 at 2:37
  • @RiccardoPerego Which testnet are you using? The time until a transaction is mined gets affected by gas price, gas and network connection. Higher gas price allow faster confirmation times, gas too high will delay transaction, bad network a transaction will take longer to reach miners. – Ismael Apr 8 at 3:28
1

The confirmation timestamp that you see on etherscan is the time when your transaction was mined, not received by the miner.

Have a look at all the transactions within a block. You will notice that they all have the same timestamp.

So, your transaction is most likely received by other nodes milliseconds after being broadcasted. However, it is mined only 5 seconds later with the next block, just like any other transaction.

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.