I have a mapping defined in my contract like below.
mapping(address => uint256) public stakers
I need to loop through it to get all of them for my frontend and other contract.
function getStakers() external returns(address[] memory, uint256[] memory) {
// I need something like below
for(i=0; i < stakers.length; i++) {
sAddress[i] = address_from_mapping;
sAmount[i] = uint256_from_mapping;
}
return (sAddress, sAmount);
}
Not sure how to implement it and also making it gas efficient as much as possible.