Mappings

Learn how to use mappings to develop smart contracts in Solidity.

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.

We'll call our contract NameService, and this smart contract will have two main features, as follows:

  • Allows recording a human-readable name associated with an Ethereum address ...