Skip to content

Instantly share code, notes, and snippets.

@kainlite
Forked from samanshahmohamadi/MappingTest.sol
Created February 5, 2021 00:49
Show Gist options
  • Save kainlite/5a555aa52f2d203d3aa9c415dae7c45c to your computer and use it in GitHub Desktop.
Save kainlite/5a555aa52f2d203d3aa9c415dae7c45c to your computer and use it in GitHub Desktop.
How to return whole mapping in solidity
pragma solidity ^0.4.25;
contract MappingTest {
mapping(uint=>address) public addresses;
uint addressRegistryCount;
function set(address userAddress) public{
addresses[addressRegistryCount] = userAddress;
addressRegistryCount++;
}
function getAll() public view returns (address[] memory){
address[] memory ret = new address[](addressRegistryCount);
for (uint i = 0; i < addressRegistryCount; i++) {
ret[i] = addresses[i];
}
return ret;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment