- Solidity allows creating contracts from other contracts. This can be done during function execution or while deploying the parent contract.
- The source code of the newly deploying contract has to be known in advance. This helps in avoiding recursive creation dependencies.
- Use the new keyword for creating contracts from other contracts:
pragma solidity ^0.4.23;contract Storage { ...}contract Parent { // Creation of new contract Address storeAddress = new Storage(); ...}
- Creating a new contract will return the address of the newly deployed contract. Convert it into an object of the contract type to access the functions directly:
Storage store = new Storage();
- Use this object for interacting with the newly deployed contract. ...