Loading...
many times some case arise when you need to deploy a brand new smart contract from the existig deployed smart contract itself.
In this smartbook we will discuss hot to do this with simple steps.
Below is the code of smart contract you wnat to deploy from an existing smart contract. You can predefine some smart contract templates and use those templates to deploy as new smart contracts.
contract Storage {
uint256 number;
event stored(uint256 _value);
function store(uint256 num) public {
number = num;
emit stored(number);
}
}
Below is the smart contract that is already deployed and with some modified function defined as public. By triggering this function we can deploy the above smart contract.
contract Deployer {
Storage a;
function deploy_sc() public {
a = new Storage();
}
function get_sc() public view returns(Storage){
return a;
}
}
// 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;
}
}