Last active
December 29, 2022 14:59
-
-
Save BellaBe/94af2910d1a7c3f88ce5268a06151beb to your computer and use it in GitHub Desktop.
Create Smart contract with new keyword, salt and initial value
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, salt and initial value | |
contract Demo{ | |
uint private simpleUint; | |
constructor() payable{} | |
function getValue() public view returns(uint){ | |
return simpleUint; | |
} | |
function setValue(uint _value) public{ | |
simpleUint = _value; | |
} | |
} | |
contract ClientWithSaltAnIntialValue { | |
function useNewKeywordWithSaltAndValue(bytes32 _salt) public returns(uint){ | |
Demo demo = (new Demo){value: 1000000000000000000, salt: _salt}(); | |
demo.setValue(10); | |
return demo.getValue(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment