Skip to content

Instantly share code, notes, and snippets.

@BellaBe
Last active December 29, 2022 14:54
Show Gist options
  • Save BellaBe/b8418958ebc5a1620d788eb77d2378ff to your computer and use it in GitHub Desktop.
Save BellaBe/b8418958ebc5a1620d788eb77d2378ff to your computer and use it in GitHub Desktop.
Create Smart contract with new keyword
// 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