Mappings

Mappings are used for a key to value mapping. This is a way to associate a value with a key. All values in this map are already initialized with all zeroes, for example, the following:

mapping (address => uint) offers; 

This example shows that offers is declared as a mapping. Another example makes this clearer:

mapping (string => uint) bids;  
bids["packt"] = 10; 

This is basically a dictionary or a hash table where string values are mapped to integer values. The mapping named bids has string packt mapped to value 10.

Get Mastering Blockchain - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.