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 6

tx.origin Misuse

InfoAccess control

Challenge

Review the name registry's caller handling and compare the code with the source page's tx.origin warning.

Starter code

pragma solidity ^0.8.0;

contract NameRegistry {
  struct User {
    string name;
  }

  mapping(address => User) public users;

  function setName(string memory _name) public {
    users[msg.sender] = User(_name);
  }

  function getName(address _user) public view returns (string memory) {
    return users[_user].name;
  }
}
Show hint

For access control, use msg.sender rather than tx.origin.