Who is the King ?

Code

T0

king is 0x0000000000000000000000000000000000000000

balance is 0

Contract address is 0x85F05208B6C3613f42366dE27BAFBd4df40a8ceb

Msg.sender is 0x5c6B0f7Bf3E7ce046039Bd8FABdfD3f9F5021678

T1

Msg.sender is 0x5c6B0f7Bf3E7ce046039Bd8FABdfD3f9F5021678

Msg.sender executes claimThrone function sending 2 ether.

msg.value > balance ( 2 > 0)

(bool sent, ) = king.call{value: balance}(“”); ( 0 balance is sent to old king address[0x0000000000000000000000000000000000000000] )

balance = msg.value; ( balance = 2 )

king = msg.sender; ( king = 0x5c6B0f7Bf3E7ce046039Bd8FABdfD3f9F5021678 )

We can show that contract’s ( 0x85F05208B6C3613f42366dE27BAFBd4df40a8ceb) balance is 2 ether.

T2

Msg.sender is 0x03C6FcED478cBbC9a4FAB34eF9f40767739D1Ff7

Msg.sender executes claimThrone function sending 3 ether.

msg.value > balance ( 3 > 2)

(bool sent, ) = king.call{value: balance}(“”); ( 2 balance is sent to old king address[0x5c6B0f7Bf3E7ce046039Bd8FABdfD3f9F5021678] )

balance = msg.value; ( balance = 3 )

king = msg.sender; ( king = 0x03C6FcED478cBbC9a4FAB34eF9f40767739D1Ff7 )

ispanyolca

Credits to Bayram Utku Uzunlar

--

--

Solidity Programming Language

Solidity basics for beginners: Learn the fundamentals of smart contract development and build your first DApp! #Solidity #Foundry #Ethereum #Opcodes #DApps