2

I am using solidity ^0.8.7. When I try to create a Struct that contains mapping, I revied an error: "Struct containing a (nested) mapping cannot be constructed." I think it is something to do with documentation changes in version 0.7.0. But I cannot find a solution.

The code:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;

...

 struct Transaction {
        address to;
        uint value;
        bytes data;
        bool executed;
        mapping(address => bool) isConfirmed;
        uint numConfirmations;
    }

...

 function submitTransaction (address _to, uint _value, bytes memory _data) public onlyOwner{
        
        uint txIndex = transactions.length;
        
        transactions.push(Transaction({to: _to, value: _value, data: _data, executed: false, numConfirmations: 0}));
            
            emit SubmitTransaction(msg.sender, txIndex, _to, _value, _data);
    }

...

Using an older version of Solidity compiles it with no problems.

Lcob
  • 21
  • 1
  • What is `transactions`?! – Ahmad Gorji Oct 25 '21 at 16:11
  • Does this answer your question? [Struct containing a (nested) mapping cannot be constructed. in solidity](https://stackoverflow.com/questions/68723493/struct-containing-a-nested-mapping-cannot-be-constructed-in-solidity) – cameel Dec 17 '21 at 07:53

0 Answers0