Skip to content

Instantly share code, notes, and snippets.

@BellaBe
Last active December 29, 2022 14:59
Show Gist options
  • Save BellaBe/ca02f8ff6155710fd4ab311b8744fa04 to your computer and use it in GitHub Desktop.
Save BellaBe/ca02f8ff6155710fd4ab311b8744fa04 to your computer and use it in GitHub Desktop.
Create Smart contract with new and salt
// 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 and salt
contract Demo{
uint private simpleUint;
constructor() payable{}
function getValue() public view returns(uint){
return simpleUint;
}
function setValue(uint _value) public{
simpleUintl = _value;
}
}
contract ClientWithSalt {
function useNewKeywordWithSalt(bytes32 _salt) public returns(uint){
Demo demo = (new Demo){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