Created
October 6, 2021 15:34
-
-
Save sepisoltani/12e6b9247a055a86e8814ba7874d0e79 to your computer and use it in GitHub Desktop.
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
contract Example{ | |
mapping (address => uint) favoriteNumber; | |
function setMyNumber(uint _myNumber) public { | |
// Update our `favoriteNumber` mapping to store `_myNumber` under `msg.sender` | |
favoriteNumber[msg.sender] = _myNumber; | |
// ^ The syntax for storing data in a mapping is just like with arrays | |
} | |
function whatIsMyNumber() public view returns (uint) { | |
// Retrieve the value stored in the sender's address | |
// Will be `0` if the sender hasn't called `setMyNumber` yet | |
return favoriteNumber[msg.sender]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment