You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The getter automatically generated by the mapping has a bug.
Environment
Remix 0.8.29
Steps to Reproduce
When I use " mapping(address => uint256[]) public holderCertificates;",the getters automatically generated by the mapping do not support getting arrays by address.
I have to manually construct the getter to retrieve the data.
The text was updated successfully, but these errors were encountered:
Hi @Un96, thanks for the follow‑up—what you’re seeing is actually by design, not a bug:
Auto‑getter signature mapping(address => uint256[]) public holderCertificates;
the compiler only emits: function holderCertificates(address _holder, uint256 _idx) external view returns (uint256);
i.e. you must supply both the holder’s address and an array index to fetch a single element. There is no holderCertificates(address) or length getter.
How to expose length or the full array
If you need to read the array length or return the entire list, add custom functions, for example:
/// @notice Get the number of certificates for a holderfunction getHolderCertificatesLength(address_holder) externalviewreturns (uint256) {
return holderCertificates[_holder].length;
}
/// @notice Get all certificate IDs for a holderfunction getHolderCertificates(address_holder) externalviewreturns (uint256[] memory) {
return holderCertificates[_holder];
}
Description
The getter automatically generated by the mapping has a bug.
Environment
Remix 0.8.29
Steps to Reproduce
When I use " mapping(address => uint256[]) public holderCertificates;",the getters automatically generated by the mapping do not support getting arrays by address.
I have to manually construct the getter to retrieve the data.
The text was updated successfully, but these errors were encountered: