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;
© 2024 OneMinuteCode. All rights reserved.