-
Notifications
You must be signed in to change notification settings - Fork 121
/
Copy pathDemo1.sol
44 lines (35 loc) · 1.13 KB
/
Demo1.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;
import "hardhat/console.sol";
contract Demo1 {
uint256 public balance;
string public name;
constructor(string memory _name) {
name = _name;
}
function getName() public view returns (string memory ) {
return name;
}
}
contract Demo2 {
address public demo1Address;//we create this variable of storing address of new contract
function createExample(string memory _name) public returns(address ) {
/*
1. This function create a new instanse of Demo1 Contract with the of d1
2. Update the demo1Address to address of d1
3. Return the Address of d1
*/
Demo1 d1 = new Demo1(_name);
demo1Address = address(d1);
return address(d1);
}
function getNameOfContract(address _addr1)public view returns(string memory) {
/*
1. This function takes address
2. Create the refrence of Demo1 and Pass this address to the Demo1 contract
3. D1 return the Name of the given address
*/
Demo1 d1 = Demo1(_addr1);
return d1.getName();
}
}