<100 subscribers
Share Dialog
Share Dialog


🗺️Mappings 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.
🗺️In the code we have a Mapping contract with a state variable declared myMap of typeValue: mapping with keyType: address and valueType: uint. 🗺️It has a function get(address), in it we can get values from the mapping, passing to it an address and it will returns a uint value. 🗺️In function set(address, uint) we can save a value in the mapping, we should provide the address (key) and the uint (value). 🗺️Last function remove(address) reset the value associated to that address to default value (in this case to 0 since it is uint type).
🗺️Next we have Nested contract, in which is declared a nested mapping, it is a mapping with keyType: address and valueType: another mapping with keyType: uint and valueType: bool. 🗺️it has a function get(address, uint), to get values from it we need to pass to it two keys, one for outside mapping and another for the inside mapping. 🗺️In function set(address, uint, bool) we can save values to the mapping passing to it three parameters, the two keys (outside and inside mapping) and the value itself. 🗺️Last function remove(address, uint) reset the value associated to that keys in the mapping to default value (in this case to false since it is bool type)

🗺️Mappings 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.
🗺️In the code we have a Mapping contract with a state variable declared myMap of typeValue: mapping with keyType: address and valueType: uint. 🗺️It has a function get(address), in it we can get values from the mapping, passing to it an address and it will returns a uint value. 🗺️In function set(address, uint) we can save a value in the mapping, we should provide the address (key) and the uint (value). 🗺️Last function remove(address) reset the value associated to that address to default value (in this case to 0 since it is uint type).
🗺️Next we have Nested contract, in which is declared a nested mapping, it is a mapping with keyType: address and valueType: another mapping with keyType: uint and valueType: bool. 🗺️it has a function get(address, uint), to get values from it we need to pass to it two keys, one for outside mapping and another for the inside mapping. 🗺️In function set(address, uint, bool) we can save values to the mapping passing to it three parameters, the two keys (outside and inside mapping) and the value itself. 🗺️Last function remove(address, uint) reset the value associated to that keys in the mapping to default value (in this case to false since it is bool type)

No comments yet