Privacy preferences

Choose separately whether we may use analytics and advertising measurement. Both stay off unless you turn them on. You can change these choices any time.

All challenges

Challenge 18

tx.origin Misuse

MediumStorage and memory

Challenge

Review activateUser. Does changing the local User value update the mapping entry?

Starter code

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract StorageBug {
  struct User {
    uint256 balance;
    bool isActive;
  }

  mapping(address => User) public users;

  function activateUser() public {
    User memory user = users[msg.sender];
    user.isActive = true;
  }

  function deposit() public payable {
    users[msg.sender].balance += msg.value;
  }
}
Show hint

A memory copy is separate from the mapping's stored struct. Update the storage entry itself.