Is this possible?

mapping(address => mapping(uint => customStruct[])) someName

Because I cannot debug and find my mistake... is there not enough gas, or it crashes on this code, while trying to fill someName.

For example:

uint length = someName[msg.sender][1].length;
someName[msg.sender][1][length].timestamp = block.timestamp;
  • Yes, it's possible to have mappings inside mappings, which you can determine because you didn't get a compile error. If you're having other problems, you need to provide more information on what they are. Apr 7, 2016 at 15:41

1 Answer 1


I suppose customStruct is a struct with timestamp property. Then your code should work. However here my test scenario:

import "dapple/test.sol";

contract MyTest is Test {

  struct Struct {
    uint timestamp;

  // Mapping test
  mapping(uint => mapping(uint => uint)) mymap;

  mapping(address => mapping(uint => Struct[])) someName;

  function testNestedMappings() {
    //@log test nested mappings
    mymap[1][2] = 42;
    //@log mymap[1][2] = `uint mymap[1][2]`
    //@log test struct array:
    //@log someName[msg.sender][1].length = `uint someName[msg.sender][1].length`
    //@log incrementing length
    //@log saving timestamp to last entry
    someName[msg.sender][1][someName[msg.sender][1].length - 1].timestamp = block.timestamp;
    //@log `uint someName[msg.sender][1][someName[msg.sender][1].length-1].timestamp`

Which run with dapple test --report outputs the following:

  test nested mappings
  LOG:  test nested mappings
  LOG:  mymap[1][2] = 42
  LOG:  test struct array:
  LOG:  someName[msg.sender][1].length = 0
  LOG:  incrementing length
  LOG:  saving timestamp to last entry
  LOG:  1460035092

Cuz i can not debug

...but this is very important

  • Thx, You gave me a hint about incrementing customStruct[] length, and it was the problem.
    – mrAkax
    Apr 8, 2016 at 3:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.