In Clarigen, a "factory" is a fancy term for combining a contract type definition (aka the "interface" or "ABI") along with a contract identifier for a given network. It's built this way because developers usually are working with their contracts on different networks, where contracts have different identifiers.
There are a few helper methods that Clarigen exposes to connect a contract definition with an identifier.
projectFactory
The most powerful way to setup your contract identifiers is to use projectFactory
, which utilizes your Clarinet deployments to determine contract IDs. For complex projects, this is the best way to keep everything configured in one place. Additionally, this is especially helpful if you're using external "requirements", which have a separate deployer on mainnet.
When using projectFactory
, you need to specify a "network", which must be one of:
devnet
testnet
mainnet
simnet
Learn more about using deployments
contractFactory
The simplest way to setup a contract is with contractFactory
, which takes two arguments: the contract types and the identifier.
contractsFactory
If you want to simply specify the single "deployer" for your contracts, this helper methods maps through each contract and sets the contract's ID to ${deployer}.${contract.name}
.
For example, if deployer
is ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM
and you have two contracts (nft
and marketplace
), then contractsFactory
will set the identifiers to ST1P...GM.nft
and ST1P...GM.marketplace
.