Quiz Entry - updated: 2026.07.30
What is the factory pattern, and how does a contract deploy another contract?
A factory is a contract that creates and manages other contracts. In Solidity you deploy a new contract instance from within a contract using the new keyword.
import "./SimpleStorage.sol";
contract StorageFactory {
SimpleStorage[] public simpleStorageArray;
function createSimpleStorage() public {
SimpleStorage ss = new SimpleStorage(); // deploys a fresh contract
simpleStorageArray.push(ss);
}
}
Contracts can deploy contracts — this is a big part of Solidity's power (contracts freely interacting is called composability). The factory imports the child's code (so it knows what to deploy), and new SimpleStorage() deploys a brand-new instance, returning a reference you can store and later call functions on. A factory typically keeps an array of everything it has deployed so it can act as a manager over all of them.
Go deeper:
Solidity docs: creating contracts via new — deploying one contract from inside another.