Type Error for Storage Factory's sfGet
method.
#20
-
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;
contract SimpleStorage {
uint256 public number; // Note that I made this variable public
function store(uint256 num) public virtual {
number = num;
}
function retrieve() public view returns(uint256) {
return number;
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;
import "./SimpleStorage.sol";
contract StorageFactory {
SimpleStorage[] public simpleStorageArray;
function createSimpleStorageContract() public {
SimpleStorage simpleStorage = new SimpleStorage();
simpleStorageArray.push(simpleStorage);
}
function sfStore(uint256 _simpleStorageIndex, uint256 _simpleStorageNumber) public {
simpleStorageArray[_simpleStorageIndex].store(_simpleStorageNumber);
}
//function sfGet(uint256 _simpleStorageIndex) public view returns(uint256) {
// return simpleStorageArray[_simpleStorageIndex].retrieve();
//}
// My version of sfGet that directly tries to return the number w/o any intermediate method like retrieve
function sfGet(uint256 _simpleStorageIndex) public view returns(uint256) {
return simpleStorageArray[_simpleStorageIndex].number;
}
} What does the error mean? ..and why? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Just replace
Solidity generates a getter function for every public variable which is used to access its content. |
Beta Was this translation helpful? Give feedback.
Just replace
simpleStorageArray[_simpleStorageIndex].number;
withsimpleStorageArray[_simpleStorageIndex].number();
in sfGet function.The code will compile correctly.
Solidity generates a getter function for every public variable which is used to access its content.