I am trying to create a mapping inside struct and then create a mapping of the struct. Take a look at below example:

    // ------------------------------------------------------------------------
    // Each Level related details are stored using `Level` struct
    // ------------------------------------------------------------------------
    struct Level{
        address payable luckyDraw;
        uint256 dividend;
        address payable topHolder;
        uint256 topInvestment;
        uint256 reversedAllowed;
        mapping(address => uint256) userReversed;
        mapping (uint => address payable) levelUsers;
        uint256 ETH_REVERSED;
        uint256 countDeposit;
        uint totalBuyers;

mapping (uint => Level) public payouts;                    // keeps record of each payout

Now here, the payouts saves record of the Level(struct), you can see the struct which have two mapping as well other than other member variables.

When I try to read the payouts, I can never read about these mappings, also it seems that I can never save any record inside these mappings. I am trying to save data for levelUsers but it doesn't seems to work, If I try to read this, it returns me 0x0000.

 // add the purchaser address to the all users array
 payouts[1].levelUsers[0] = msg.sender;

address payable user = payouts[1].levelUsers[0];

The user is always 0x000, seems it never saves successfully

Are my declarations all good?

  • Please elaborate on it doesn't seems to work (how do you determine that, what error do you get, etc). Apr 2 '20 at 15:35
  • edited. please read thanks for ur time Apr 2 '20 at 15:37
  • How do you determine that The user is always 0x000? Apr 2 '20 at 15:39
  • Because I am saving the user like this and then reading accounts information from compiler. accounts[user].luckyDrawWinning = 10; So, in accounts mapping when I enter the address of user the luckDrawWinning is always zero. Apr 2 '20 at 15:41
  • mapping(address => Account) accounts; struct Account{ uint luckyDrawWinning;} Apr 2 '20 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.