Last active
December 29, 2022 14:54
-
-
Save BellaBe/b8418958ebc5a1620d788eb77d2378ff to your computer and use it in GitHub Desktop.
Create Smart contract with new keyword
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.13; | |
// usage: one contract(client) deploys and creates a new insatnce of another contract(Demo) by using new keyword | |
contract Demo { | |
uint private simpleUint; | |
constructor() payable{} | |
function getValue() public view returns(uint){ | |
return simpleUint; | |
} | |
function setValue(uint _value) public{ | |
simpleUint = _value; | |
} | |
} | |
contract Client { | |
function useNewKeyword() public returns(uint){ | |
Demo demo = new Demo(); | |
demo.setValue(10); | |
return demo.getValue(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment