solidity lesson 2

anish jain
1 min readNov 17, 2021

--

well in last lesson we see how we start with solidity and learn some basic concept about it. Here we learn about how we can call the one contract form other

1 import "your contract name" // ex import "./SimpleStorage.sol"2 contract SimpleSmartContractFactory{3 SimpleStorage[] public simpleStorageArray;
4 fucntion createSimpleStorageContract() public{
5 SimpleStorage simepleStorage = new SimpleStorage();
6 simpleStorageArray.push(simpleStorage);
}
}

lets explain what is above code does

line 2 first we import our other contract “similar imports like in JS”

line 3 — in last lesson we create array of Person type now similarly we create array of SimpleStorage it means we can push SimpleStorage type data into this

line 4/5 create a public functions which helps to insert data into block and push it into our array

line 5 is how we define variable of type contract “pretty similar to JS”

How to use other contract function into other contract

for this we need 2 things one it’s address and other is “ABI

more about ABI later

how to address

SimpleStorag ss = SimpleStorage(address(simpleStorageArray[index]))

now with this ss variable you can access any of its functions.

how to do Inheritance with soliditycontract B is A{}

yes is that simple

--

--

anish jain
anish jain

Written by anish jain

like to create things,and some time to break them to get indepth knowledge,stronly believe in learning never exhaust the mind

No responses yet