Loading...
Creating a smart contract via smart contract has many advantages and use cases over manually creating and deploying smart contracts.
Contract to be deployed will be a simple storage smart contract as follows
contract Storage {
uint256 number;
event stored(uint256 _value);
function store(uint256 num) public {
number = num;
emit stored(number);
}
}
We will create one variable of type Storage, which is our contract to be deployed, to store created contract's instance.
contract Deployer {
Storage a;
function deploy_sc() public {
a = new Storage();
}
function get_sc() public view returns(Storage){
return a;
}
}
Here we need to deploy Deployer smart contract and call deploy_sc method.
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;
contract Storage {
uint256 number;
event stored(uint256 _value);
function store(uint256 num) public {
number = num;
emit stored(number);
}
}
contract Deployer {
Storage a;
function deploy_sc() public {
a = new Storage();
}
function get_sc() public view returns(Storage){
return a;
}
}