Focus mode

Smart Contract Development with Solidity

Mappings

Code from video: https://solidity-by-example.org/mapping/ 

You can access the video content in Turkish prepared by İTÜ Blockchain here: https://www.youtube.com/watch?v=aZDdyhfesEc&list=PLby2HXktGwN4Cof_6a8YwlMrboX8-hs73&index=7 

Mapping in Solidity acts like a hash table or dictionary in any other language. These are used to store data values in key:value pairs. In terms of mapping, the key data is not stored in a mapping, only its keccak256 hash is used to look up the value. The KeyType can be any built-in value type, bytes, string, or any contract or enum type. Other user-defined or complex types, such as mappings, structs or array types are not allowed. ValueType can be any type, including mappings, arrays and structs.

Mappings are mostly used to associate the unique Ethereum address with the associated value type.

  • Maps are created with the syntax mapping (keyType => valueType).
  • The keyType can be any built-in value type, bytes, string, or any contract.
  • valueType can be any type including another mapping or an array.
  • Mappings are not iterable.
  • Mappings can be counted so that we can know how many values are stored in mapping.

Resources:

You can find detailed further information from Solidity Official documentation(in English):  

https://docs.soliditylang.org/en/v0.8.15/types.html#mapping-types 

https://solidity-by-example.org/mapping/

https://www.geeksforgeeks.org/solidity-mappings/

Comments

You need to enroll in the course to be able to comment!