paint-brush
How to Solve "Struct Containing a (Nested) Mapping Cannot be Constructed" in Solidityby@ndehouche
5,014 reads
5,014 reads

How to Solve "Struct Containing a (Nested) Mapping Cannot be Constructed" in Solidity

by Nassim Dehouche2mMarch 17th, 2022
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

A compilation error is encountered when you try to instantiate a struct that contains a mapping as an attribute. This type of one-to-many data structure can be useful, for instance, to encode a marketplace for time-limited licenses to some content. But this type of structure cannot be equivalently modeled with a separate mapping for licenses. The workaround is quite simple, we just have to declare the struct in storage before we instantiate a pointer to it.
featured image - How to Solve "Struct Containing a (Nested) Mapping Cannot be Constructed" in Solidity
Nassim Dehouche HackerNoon profile picture
Nassim Dehouche

Nassim Dehouche

@ndehouche

Operations Researcher, Web3 Subject-Matter Expert. Technology Investment, Karaoke, Generative Art.

About @ndehouche
LEARN MORE ABOUT @NDEHOUCHE'S
EXPERTISE AND PLACE ON THE INTERNET.
L O A D I N G
. . . comments & more!

About Author

Nassim Dehouche HackerNoon profile picture
Nassim Dehouche@ndehouche
Operations Researcher, Web3 Subject-Matter Expert. Technology Investment, Karaoke, Generative Art.

TOPICS

THIS ARTICLE WAS FEATURED IN...

Permanent on Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite