This repository was archived by the owner on Jul 13, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed
Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ layout : post
3+ published : true
4+ title : ' Mapping Named Parameters'
5+ date : ' 2023-02-08'
6+ author : Matheus Aguiar
7+ category : Explainers
8+ ---
9+
10+ ### Intro
11+ [ Solidity 0.8.18] ( https://github.com/ethereum/solidity/releases/tag/v0.8.18 ) introduced a language feature that
12+ was well received by many in the community: Mapping types now have named parameters.
13+ This new feature opens the possibility to name one or more of the parameters, as we show in the following example.
14+
15+ Example 1:
16+
17+ ``` solidity
18+ mapping(string user => uint256 balance) public balanceOf;
19+ mapping(address key => string) public dictionary;
20+
21+ ```
22+ Notice that the naming of parameters is optional and unnamed mapping declarations are still valid in the language.
23+ It is particularly useful in situations where there are nested mappings, such as the one presented in the next example.
24+
25+
26+ Example 2: (Nested mappings)
27+
28+ ``` solidity
29+
30+ mapping(address owner => mapping(address spender => uint256 balance)) public allowance;
31+
32+ ```
33+ ### Advantages
34+
35+ Tooling can get more info in the generated code.
36+ TODO: Elaborate on the example of https://github.com/ethereum/solidity/issues/11407 bellow
37+
38+ ```
39+ // solidity
40+ mapping(address => mapping(address => uint256)) public allowance;
41+
42+ // typescript
43+ // generated typing
44+ allowance(arg0: string, arg1: string, overrides?: CallOverrides): Promise<BigNumber>;
45+
46+ // would be great to instead have
47+ allowance(spender: string, owner: string, overrides?: CallOverrides): Promise<BigNumber>;
48+
49+ ```
50+ Code in general is easier to read, which helps not only in maintenance but also makes faster to understand code.
You can’t perform that action at this time.
0 commit comments