LOGBOOK

HELP

Quiz Entry - updated: 2026.07.30

What is the Factory Contract pattern, and why keep the template on-chain rather than in a code repository?

Deploy a template contract once that acts as a factory, minting customised contract instances on demand — keeping the template on-chain guarantees every instance is consistent, which an off-chain source repository cannot.

  • Problem. An application may need many instances of a standard contract, each slightly customised (for example, one contract per business-process instance). If the template lives off-chain in a code repository, its source can be modified independently, so different instances may silently diverge — consistency is not guaranteed.
  • Solution. Deploy a factory contract once from the off-chain source; it holds the definition of one or more contracts. Passing parameters to the factory instantiates a customised instance — directly analogous to a class in object-oriented programming, where each instance is an object with its own state but the template's structure. Every instance is therefore guaranteed to match the on-chain template.
  • Benefits. Security/consistency (on-chain template guarantees instances match) and efficiency (instances are made by a simple function call).
  • Drawbacks. On a public chain, deployment cost (deploying the factory) and function-call cost (each new instance costs gas to create). It pairs naturally with a contract registry to track the instances it produces.

From Quiz: IOTHACK / Design Patterns for Blockchain Applications | Updated: Jul 30, 2026