Skip to content

Instantly share code, notes, and snippets.

@sagarduwal
Created July 11, 2021 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sagarduwal/71ab106116372057ffcc87d6efaf8f94 to your computer and use it in GitHub Desktop.
Save sagarduwal/71ab106116372057ffcc87d6efaf8f94 to your computer and use it in GitHub Desktop.
Solidity Struct Example
// 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