Search icon
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Solidity Programming Essentials

You're reading from  Solidity Programming Essentials

Product type Book
Published in Apr 2018
Publisher Packt
ISBN-13 9781788831383
Pages 222 pages
Edition 1st Edition
Languages

Table of Contents (17) Chapters

Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
1. Introduction to Blockchain, Ethereum, and Smart Contracts 2. Installing Ethereum and Solidity 3. Introducing Solidity 4. Global Variables and Functions 5. Expressions and Control Structures 6. Writing Smart Contracts 7. Functions, Modifiers, and Fallbacks 8. Exceptions, Events, and Logging 9. Truffle Basics and Unit Testing 10. Debugging Contracts 1. Other Books You May Enjoy Index

Mappings


Mappings are one of the most used complex data types in Solidity. Mappings are similar to hash tables or dictionaries in other languages. They help in storing key-value pairs and enable retrieving values based on the supplied key.

Mappings are declared using the mapping keyword followed by data types for both key and value separated by the => notation. Mappings have identifiers like any other data type and they can be used to access the mapping.

An example of mapping is as follows:

Mapping ( uint => address ) Names ;

In the preceding code, the uint data type is used for storing the keys and the address data type is used for storing the values. Names is used as an identifier for the mapping.

Although it is similar to a hash table and dictionary, Solidity does not allow iterating through mapping. A value from mapping can be retrieved if the key is known. The next example illustrates working with mapping. A counter of type uint is maintained in a contract that acts as a key and address...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}