Created
January 15, 2019 09:40
-
-
Save samanshahmohamadi/d0d43034e45ccadfd48ce97ed0bd1aba to your computer and use it in GitHub Desktop.
How to return whole mapping in solidity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
I've noted that the response of this is similar to this (I'm using string array instead address array):
{ "0": "string[]: Test1,Test2" }
How catcheable is it this for Dapp? What does finally receive JS? Thanks!