docs/vyper-by-example/factory.rst
.. index:: factory pattern
Factory Pattern
.. _factory:
.. warning::
This is example code for learning purposes. Do not use in production without thorough review and testing.
The factory pattern deploys and registers multiple contract instances. This example shows a factory that registers exchanges and routes trades between them.
.. literalinclude:: ../../examples/factory/Factory.vy :language: vyper :linenos:
.. literalinclude:: ../../examples/factory/Exchange.vy :language: vyper :linenos:
How the pattern works:
codehashfactory.register() to register itselffactory.trade()The msg.sender.codehash check ensures only legitimate exchange contracts can register.