I've declared a mapping mapping (address => uint) public stakeholderId; in another contract. I want to copy it from the contract, so I've declared a mapping and want to assign the mapping to it:

contract ActivityInterface{
    address CongressAddress = 0x1;
    Congress temp = Congress(CongressAddress);
    mapping (address => uint) stakeholderId = temp.stakeholderId;

However, why does it show the following error for the line mapping (address => uint) stakeholderId = temp.stakeholderId;:

Type function (address) returns (uint256) is not implicitly convertible to expected type mapping(address => uint256).

1 Answer 1


Solidity generates getter functions for public state variables.

Those functions can be used to access other contract's state.

In your example, temp.stakeholderId is a such autogenerated function. You can call it to get stakeholder id by address:

uint id = temp.stakeholderId(someAddress);

So, back to error message temp.stakeholderId has type function (address) returns (uint256) and it can not be converted to mapping(address => uint256).

As to your original intention, maps are reference types, and I don't think it is easy to copy map from one contract to another without some loop.

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.