Skip to content

Instantly share code, notes, and snippets.

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