Lesson 3: Query about SimpleStorage Array and SimpleStorage Object. #936
-
Hi I'm a little confused about what this code is doing. What is happening in the line "SimpleStorage[] public simpleStorageArray?" What does the line "SimpleStorage simpleStorage = new SimpleStorage();" doing? //
contract StorageFactory {
SimpleStorage[] public simpleStorageArray;
function createSimpleStorageContract() public {
simpleStorage simpleStorage = new SimpleStorage();
simpleStorageArray.push(simpleStorage);
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
SimpleStorage[] public simpleStorageArray; This is called declaring an Array in solidity. In that case, this array type is - simpleStorage simpleStorage = new SimpleStorage();
+ SimpleStorage simpleStorage = new SimpleStorage(); There is a typo mistake, correct it. SimpleStorage simpleStorage = new SimpleStorage(); This line is creating an object of the SimpleStorage contract and we are pushing to the array after it. |
Beta Was this translation helpful? Give feedback.
-
I will keep this as simple as possible for your ease: Your doubts: "What is happening in the line Note: if you are comfortable with OOP languages, treat Contracts like Classes
Hope this helps! |
Beta Was this translation helpful? Give feedback.
@p0lpixel
SimpleStorage[] public simpleStorageArray;
This is called declaring an Array in solidity. In that case, this array type is
SimpleStorage
.There is a typo mistake, correct it.
This line is creating an object of the SimpleStorage contract and we are pushing to the array after it.