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 (
  requests.length, // TypeError: Member "length" not found or not visible after argument-dependent lookup in mapping

How to find the length of this requests mapping?

1 Answer 1


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?

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.