I want to access a single value of a mapped struct from another contract. For now, I know how to return all values of the struct by using the following code:

function getUnitById(uint256 _id) public view returns (uint256 id, string name, uint256 attack, uint256 defense, uint256 heal, uint256[] questsCompleted) {
    return unitsContract.tokenToUnit(_id);

but what do I have to do to access only one single value?

return unitsContract.tokenToUnit(_id).questsCompleted;

would make sense in my opinion but that does not work at all.

Did anyone get a working solution?

1 Answer 1


I don't think it is possible till solidity version 0.4.24.

You are calling a functionunitsContract.tokenToUnit(_id) whose returun type is tuple.

You are not accessing mapping and therefore it is not possible to get a particular attribute using unitsContract.tokenToUnit(_id).questsCompleted.

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.