0

Assuming I have a Smart Contract with this code:

contract TestContract {
  uint256 var1 = 0;

  function test()
  {
     if (var1 == 0)
     {
        var1 = 1;
        throw;
     }
  }
}

Assuming 2 different addresses call the test() function in the same block, will both transactions get the throw or only the first one?

1 Answer 1

2

All calls to test() will throw with that program. When a transaction throws, all state changes are reversed, so var1 will always stay 0.

If you write it like this:

contract TestContract {
  uint256 var1 = 0;

  function test()
  {
     if (var1 == 0)
     {
        var1 = 1;
     }
     else
     {
        throw;
     }
  }
}

...the first call to test() will change var1 from 0 to 1

and all subsequent calls to test() will throw.

Even if the are in the same block.

The state of the smart contract is changed after each transaction, not only after each block.

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.