0
0
Blockchain / Solidityprogramming~5 mins

Mappings in Blockchain / Solidity - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a mapping in blockchain smart contracts?
A mapping is like a digital dictionary that links one value (a key) to another value. It helps store and find data quickly in smart contracts.
Click to reveal answer
beginner
How do you declare a mapping in Solidity?
You write: mapping(KeyType => ValueType) public name; where KeyType is the type of the key and ValueType is the type of the value stored.
Click to reveal answer
intermediate
Can you iterate over all keys in a mapping directly?
No, mappings do not store keys or allow iteration. You must keep a separate list of keys if you want to loop through them.
Click to reveal answer
beginner
What happens if you access a mapping with a key that does not exist?
You get the default value for the value type (like 0 for numbers or false for booleans), because mappings always return a value even if the key was never set.
Click to reveal answer
beginner
Why are mappings useful in blockchain smart contracts?
They let you store and quickly find data linked by keys, like user balances or permissions, without using lots of storage or complex searching.
Click to reveal answer
How do you declare a mapping from addresses to unsigned integers in Solidity?
Amapping(uint, address) public balances;
Bmapping(uint => address) public balances;
Cmapping(address => uint) public balances;
Dmapping(address, uint) public balances;
What value do you get when accessing a mapping with a key that was never set?
AAn error is thrown
BThe default value of the value type
CNull
DRandom data
Can you loop through all keys in a mapping directly?
ANo, mappings do not store keys for iteration
BYes, mappings support iteration
COnly if keys are numbers
DOnly in test environments
What is a common use of mappings in smart contracts?
ARunning loops
BCreating user interfaces
CCompiling code
DStoring user balances
Which of these is NOT a valid key type for a mapping in Solidity?
Amapping
Buint
Cstring
Daddress
Explain what a mapping is and how it works in blockchain smart contracts.
Think of it like a digital dictionary that stores data linked by keys.
You got /4 concepts.
    Describe how you would store and retrieve user balances using a mapping in Solidity.
    Focus on how keys and values relate and how to get a balance.
    You got /5 concepts.