1

In sol 0.8.10 I used this approach given by this

contract Campaign {
struct Request {
    string description;
    uint value;
    address recipient;
    bool complete;
    uint approvalCount;
    mapping(address => bool) approvals;
}

uint numRequests; mapping (uint => Request) requests;

function createRequest(string memory description, uint value, address recipient) public restricted {
Request storage r = requests[numRequests++]; r.description = description; r.value = value; r.recipient = recipient; r.complete = false; r.approvalCount = 0; } }

function getSummary() public view returns (uint, uint, uint, unit, address) { return ( minimumContribution, address(this).balance, requests.length, // TypeError: Member "length" not found or not visible after argument-dependent lookup in mapping approversCount, manager ); }

How to find the length of this requests mapping?

aiky k.
  • 13
  • 6

1 Answers1

0

You cannot iterate over the keys or get a mapping's length, but you do track the number of elements in your mapping in numRequests

See this to complete your approach: How to loop through mapping in solidity?

DrGorilla.eth
  • 1,276
  • 8
  • 19