0

I has code which sends ETH and ERC-20 and of which I want to make sense:

let tx1 = await transferETH(amount, privateKey);
console.log(`${tx1.hash}`);
const receipt1 = await tx1.wait();
console.log(`Done`);

And

let tx2 = await transferERC20(amount, privateKey);
console.log(`${tx2.hash}`);
const receipt2 = await tx2.wait();
console.log(`Done`);

I wonder, is it actually possible for a TX to produce hash before it's been mined into a block?

And which procedure takes at least 10 minutes, as per design of Ethereum protocol:

a) transfer and producing a hash - transferETH/ERC20? Or b) mining a TX into a block - wait()?

Or perhaps a) and b) are more or less close in terms of time they take? One goes immediately, in seconds, after the other, that is.

1 Answer 1

2

I wonder, is it actually possible for a TX to produce hash before it's been mined into a block?

The short answer is yes.

The slightly longer answer is, the transaction hash is a fingerprint of the RLP encoded transaction data. For example, here's a link to the go-ethereum repository showing the components of the legacy transaction type: https://github.com/ethereum/go-ethereum/blob/master/core/types/tx_legacy.go#L26-L34. After a transaction is signed the transaction data is serialized using RLP and then submitted to the network (typically via an RPC call like eth_sendRawTransaction).

So yes, one could create and sign a transaction and determine the hash of it prior to even submitting the transaction to the network.

And which procedure takes at least 10 minutes, as per design of Ethereum protocol:
a) transfer and producing a hash - transferETH/ERC20? Or b) mining a TX into a block - wait()?

Since the transition to POS, a new block is produced every 12 seconds. So your 10 minute wait time is due to the priority your transaction is given in the mempool. Your transaction will be mined faster if you were to increase your maxPriorityFeePerGas (or gasPrice if still using the legacy transaction type).

3
  • Since the transition to POS, a new block is produced every 12 seconds. So your 10 minute wait time is due to --> My question isn't "what's it due to?". My question is "which of the 2 procedures takes 10 minutes: producing TX or mining it?
    – Camila326
    Mar 15, 2023 at 12:37
  • Since the transition to POS, a new block is produced every 12 seconds. So your 10 minute wait time is due to the priority your transaction is given in the mempool. --> then I don't understand. Does it still remain 10 minutes? Or has it changed, since PoS introduction, to 12 seconds?
    – Camila326
    Mar 15, 2023 at 12:38
  • Let me rephrase then. Of the two procedures, the reason you are waiting 10 minutes is because of the mining process (since Ethereum isn't POW anymore, it wouldn't be called mining though). Block producers likely aren't selecting your transaction to be included in the block they're building because the fee you are paying is too low relative to other transactions in the mempool. Your wait time (time it takes for the transaction to be included in a block) is directly linked to the gas price / priority fee you are paying. Increase it, and your wait time will decrease. Mar 16, 2023 at 2:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.