Search⌘ K
AI Features

Mappings

Explore how to use mappings in Solidity to efficiently associate keys with values, enabling practical smart contracts like a NameService. Understand mapping syntax, default values, and limitations while implementing a contract that links human-readable names to Ethereum addresses.

We’ve already learned about arrays, the first built-in data structure provided by Solidity. While they're very handy, in many cases, we need to track multiple key-value pairs and quickly get a value for a particular key. While this could be implemented using arrays, it would be slow and expensive to execute.

To efficiently support this host of use cases, Solidity has another data structure called mapping. We'll learn how we can use mappings in Solidity and apply them to implement a new smart contract.

Name service

To make this lesson more practical, we start with implementing a new smart contract. This smart contract will allow registering human-readable names for Ethereum addresses, which can otherwise be long and cumbersome to use and share. ...