Created
April 24, 2023 16:33
-
-
Save pcaversaccio/49a4d746884f18905460dac559b994ae to your computer and use it in GitHub Desktop.
Access nested struct withing Solidity.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: WTFPL | |
pragma solidity ^0.8.19; | |
contract NestedStruct { | |
struct Inside { | |
address a1; | |
address a2; | |
address a3; | |
} | |
struct Outside { | |
uint256 num1; | |
bytes32 byte1; | |
address a4; | |
address a5; | |
bool bool1; | |
address a6; | |
mapping(uint256 => Inside) insides; | |
} | |
Outside internal outside; | |
function setValues() public { | |
outside.insides[1].a1 = address(1); | |
outside.insides[1].a2 = address(2); | |
outside.insides[1].a3 = address(3); | |
} | |
function getter(uint256 idx) public view returns (address, address, address) { | |
return (outside.insides[idx].a1, outside.insides[idx].a2, outside.insides[idx].a3); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment