This document summarizes the integration of the CreatorIPCollectionFactory contract into the Story Protocol pipeline.
The factory contract (CreatorIPCollectionFactory) has been deployed on Story Mainnet and is now integrated into the collection creation flow. The factory uses CREATE2 for deterministic collection addresses and deploys TokenERC721 contracts (Story Protocol's NFT contract) for each creator.
- Updated ABI to match the new
CreatorIPCollectionFactoryinterface - Added support for
bytecodeparameter indeployCreatorCollection - Updated to use TokenERC721 collection ABI (instead of custom CreatorIPCollection)
- Added functions for factory configuration and bytecode management
- Server-side API route for factory-based collection deployment
- Requires
FACTORY_OWNER_PRIVATE_KEYenvironment variable - Handles collection deployment via factory contract
- Modified
getOrCreateCreatorCollectionto use factory first, then fallback to SPG - Added factory deployment logic with proper error handling
- Maintains backward compatibility with SPG-based collection creation
- Added documentation for factory-related environment variables:
NEXT_PUBLIC_CREATOR_IP_FACTORY_ADDRESSFACTORY_OWNER_PRIVATE_KEYCOLLECTION_BYTECODE
Deployed Address (Mainnet): 0xd17c79631eae76270ea2ace8d107c258dfc77397
Features:
- Uses CREATE2 for deterministic collection addresses
- Deploys TokenERC721 contracts (Story Protocol's NFT contract)
- Creator owns collection from day one (set as DEFAULT_ADMIN_ROLE)
- Only factory owner can deploy collections (
onlyOwnermodifier)
To enable factory-based collection deployment, add these to your .env.local:
# Factory contract address (required for factory-based deployment)
NEXT_PUBLIC_CREATOR_IP_FACTORY_ADDRESS=0xd17c79631eae76270ea2ace8d107c258dfc77397
# Factory owner private key (server-side only, required for deployments)
FACTORY_OWNER_PRIVATE_KEY=0x...
# TokenERC721 creation bytecode (server-side only, required for deployments)
COLLECTION_BYTECODE=0x...How to get the bytecode:
- Compile the TokenERC721 contract using Foundry:
forge build --contracts contracts/CreatorIPCollection.sol
- Extract bytecode from:
out/CreatorIPCollection.sol/TokenERC721.json - Copy the
bytecode.objectfield
- Check Database: First checks if creator already has a collection in the database
- Check On-Chain: Verifies collection exists on-chain via factory contract
- Deploy via Factory (if configured):
- Uses factory owner's private key to deploy
- Deploys TokenERC721 collection with creator as owner
- Stores collection address in database
- Fallback to SPG (if factory not configured or deployment fails):
- Uses Story Protocol SPG to create collection
- Maintains backward compatibility
The minting and IP registration flow remains unchanged:
- Uses
mintAndRegisterIpormintAndRegisterIpAndAttachPilTermsfrom SPG service - Works with both factory-deployed collections and SPG collections
- Creator receives NFTs via
recipientparameter
- Deterministic Addresses: CREATE2 allows pre-computing collection addresses
- Creator Ownership: Collections are owned by creators from deployment
- Better UX: Can show collection address before deployment
- Backward Compatible: Falls back to SPG if factory not configured
- Gas Efficiency: Factory pattern can reduce gas costs for batch deployments
FACTORY_OWNER_PRIVATE_KEYis sensitive and must be kept secure- Never commit private keys to version control
- Use secure key management in production (e.g., Vercel environment variables)
- Factory owner has full control over collection deployments
To test the factory integration:
- Ensure all environment variables are configured
- Call
getOrCreateCreatorCollectionwith a creator address - Verify collection is deployed via factory (check transaction on StoryScan)
- Verify collection address matches computed address (CREATE2)
- Check that
FACTORY_OWNER_PRIVATE_KEYis set correctly - Verify factory owner has sufficient balance for gas fees
- Ensure
COLLECTION_BYTECODEmatches the bytecode hash in factory contract - Check factory contract is deployed and accessible
- Factory not configured: Check
NEXT_PUBLIC_CREATOR_IP_FACTORY_ADDRESSis set - Factory deployment failed: Check error logs for specific failure reason
- Missing bytecode: Ensure
COLLECTION_BYTECODEis set
- Batch deployment support for multiple creators
- Collection address pre-computation UI
- Factory ownership transfer utilities
- Collection deployment monitoring and analytics