Created
January 29, 2026 16:42
-
-
Save jdev-htetwaiyan/b9d10631f807dbedf6bbd8315c091ab4 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.28+commit.7893614a-revive-0.1.0-dev.12.js&optimize=false&runs=200&gist=
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SPDX-License-Identifier: MIT | |
| pragma solidity ^0.8.0; | |
| error AlreadyRegistered(); | |
| error PersonNotFound(address userAddress); | |
| contract PersonRegistry { | |
| struct Person { | |
| string name; | |
| uint256 age; | |
| bool isRegistered; | |
| } | |
| // to store a person together with unique wallet address | |
| mapping(address => Person) public people; | |
| // add a new person to the contract | |
| function addPerson(string memory _name, uint256 _age) public { | |
| if (people[msg.sender].isRegistered) { | |
| revert AlreadyRegistered(); // save more gas(money) | |
| } | |
| people[msg.sender] = Person(_name, _age, true); | |
| } | |
| // find with wallet address | |
| function getPerson(address _userAddress) public view returns (string memory, uint256) { | |
| Person memory person = people[_userAddress]; | |
| if (!person.isRegistered) { | |
| revert PersonNotFound(_userAddress); | |
| } | |
| return (person.name, person.age); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment