0

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 1

0

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];
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.