0
pragma solidity >=0.4.21 <0.7.0;

contract Bid{

    mapping(string=>uint) propertyVoteCount;
    mapping(string=>mapping(string => bool)) propertyUserVoted;
    
    function vote(string memory propertyId, string memory userId)public returns (bool){
        require(propertyVoteCount[propertyId]<10, "Bidding is Over");
        mapping (string => bool) storage userIds = propertyUserVoted[propertyId];
        require(!userIds[userId], "User has already voted");
        propertyVoteCount[propertyId]++;
        userIds[userId] = true;
        propertyUserVoted[propertyId] = userIds; //Getting the error here

    }
}

1 Answer 1

1

Because you are assigning the all mapping instead of assigning a value to an element of the mapping.

Couldn't you achieve the same thing with the code below? Why the added complexity? Did you find that code somewhere?

pragma solidity >=0.4.21 <0.7.0;

contract Bid{

    mapping(string=>uint) public propertyVoteCount;
    mapping(string=>mapping(string => bool)) public propertyUserVoted;
    
    function vote(string memory propertyId, string memory userId)public returns (bool){
        require(propertyVoteCount[propertyId]<10, "Bidding is Over");
        require(!propertyUserVoted[propertyId][userId], "User has already voted");
        propertyVoteCount[propertyId]++;
        propertyUserVoted[propertyId][userId] = true;
    }
}
1
  • But, by technically speaking, why we couldn't make such assignment? It is possible in other languages, e.g. Java\Kotlin.
    – Gleichmut
    Nov 14, 2022 at 3:30

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.