0

As an example take the following test contract:

pragma solidity ^0.4.24;


contract DoubleCall {
    address public superHero;
    uint256 public price = 1 ether;

    function becomeSuperHero() public payable{
        require(msg.value >= price);
        superHero = msg.sender;
        price = price * 2;
    }
}

What will superHero be if two accounts send a transaction calling the contract's becomeSuperHero() - both sending 1Eth and the same amount of gas. Both transactions should be included within the same block.

What is the outcome?

1

Transactions are included in a block in a specific order. In your example, even if both transactions are in the same block, one will come before the other.

In this case, the first tx in the block's tx list will become the super hero, and the price will increase to 2 ETH.

When the second tx is executed, it is executed in a version of the smart contract where the first tx is already mined. This will cause it to fail, since 1 ETH is less than the required price.

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.