Created
July 11, 2021 18:57
-
-
Save sagarduwal/71ab106116372057ffcc87d6efaf8f94 to your computer and use it in GitHub Desktop.
Solidity Struct Example
This file contains 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: GPL-3.0 | |
pragma solidity >=0.7.0 <0.9.0; | |
contract StructDemo { | |
struct User { | |
uint256 level; | |
uint256 status; | |
} | |
mapping(address => User) public userList; | |
User userDetail = User(1, 1); | |
constructor() public { | |
userList[msg.sender] = userDetail; | |
} | |
function updateUserLevel(uint256 userLevel) public { | |
userDetail.level = userLevel; | |
} | |
function getUserDetail(address userAddress) public returns (User memory) { | |
return userList[userAddress]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment