So I've been learning solidity for the past month through an online course. The bad thing is there are some basic things I just cant get the hang on like in Mapping the difference between keys and values. Also what does mapping even do? I dont understand the core of what its used for. I know this question may be ridiculous to advanced programmers but help a girl out pls...
1 Answer
Mapping works as Dictionary, the key is the unique value which you want to access its related data later. For example if you want to keep a balance for an address that means you will search later in this dictionary by key = address and you will get the value = uin256.
mapping (address => uint256) private balances;
function set(address user, uint256 balance) public returns (bool) {
balances[user] = balance;
}
function get(address user) public view returns (uint256) {
return balances[user];
}