I am working on a very simple smart contract that can save the value and get it back as a list. The code is as below.
contract lister {
mapping(int => string) list;
int id = 0;
function getList() returns ( /*HERE*/ ) {
return list;
}
function setItemToList(string str) {
list[id] = str;
id++;
}
}
I want to return the list from the getList function, but it doesn't work. How can I return the list?
Source: https://stackoverflow.com/questions/37606839/how-to-return-mapping-list-in-solidity-ethereum-contract This question is authorized to change the same condition (Available under the https://creativecommons.org/licenses/by-sa/3.0/deed.ko ) license.
ethereum solidity
It is difficult to access large-sized lists, arrangements, etc. in Solidity. You probably haven't seen much of it in other contracts. In the case of the questioner's code, it is possible to create a function that uses the index to access a single value, and to access all indexes using repetitive statements.
If you put public in front of the list, you will be able to access it from the getList.
mapping(int => string) public list;
1947 M2 Mac fails to install rbenv install 3.1.3 due to errors
1839 I want to run pyautogui without remote connection on Windows 10 in the cloud
3145 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
2690 I want to display multiple lines with FFmpeg subtitles.
© 2026 OneMinuteCode. All rights reserved.