2

if two of transactions initiating the same smart contract in one block during state transition cycle, what will happen to the contract account balance and the variables(or data) changes through execution of the code? will the later one overwrite the former one?

Thank you!

3

Which block the transaction is processed in actually does not matter here. To simplify this very concern, everything happens in sequence. This means a single transaction is considered at a time - and if it modifies state that is complete before the next transaction is processed.

So although two transactions may appear in a single block, one transaction was processed before the other. When writing logic in your contract, it is effectively the same as if each block could only hold 1 transaction.

It helps to make Solidity development easier.

1

While @Hardly's answer is correct I believe a bit more information would help.

The order in which transactions appear in a block is up to the miners. So whoever wins the mining game for that block decides which transactions appear in the block and in which order. There is no certain way to affect this behaviour - increasing your transaction's gas price will probably mean it gets added faster in a block (probably even before another transaction which is waiting) but there's no guarantee.

So, as Hardly said, the transactions will be processed in sequence. They are not processed in parallel. So if the two transactions try to perform conflicting actions (such as both sending the full balance of an address elsewhere) the first one to be mined and included in a block wins and the other one gets reverted.

All transactions in a mined block are always guaranteed to be valid and they do not contradict each other.

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.