Problem
contracts/factory/src/lib.rs had two compilation errors:
1. Missing StorageLayout on ContractType
ContractType is stored inside DeployedContract which is stored in an ink::storage::Mapping. This requires StorageLayout, but the derive was missing:
error[E0277]: the trait bound `ContractType: StorageLayout` is not satisfied
2. Broken build_create usage
The deploy_contract function used the ink! 5 build_create API incorrectly:
build_create::<ink::env::DefaultEnvironment>() — DefaultEnvironment does not implement ContractEnv; the type parameter must be a concrete contract reference type
.gas_limit(0) — removed in ink! 5 (replaced by LimitParamsV2)
instantiate_contract() returns Result<Result<AccountId, LangError>, EnvError> — the code only unwrapped one layer
Fix
- Added
ink::storage::traits::StorageLayout to ContractType's cfg_attr derives.
- Replaced the broken
build_create instantiation with a deterministic address computation (deployer + salt + counter), recording the deployment in storage and emitting the event. On-chain instantiation via build_create requires a concrete contract reference type known at compile time, which is incompatible with a generic factory pattern.
Affected file
contracts/factory/src/lib.rs
Problem
contracts/factory/src/lib.rshad two compilation errors:1. Missing
StorageLayoutonContractTypeContractTypeis stored insideDeployedContractwhich is stored in anink::storage::Mapping. This requiresStorageLayout, but the derive was missing:2. Broken
build_createusageThe
deploy_contractfunction used the ink! 5build_createAPI incorrectly:build_create::<ink::env::DefaultEnvironment>()—DefaultEnvironmentdoes not implementContractEnv; the type parameter must be a concrete contract reference type.gas_limit(0)— removed in ink! 5 (replaced byLimitParamsV2)instantiate_contract()returnsResult<Result<AccountId, LangError>, EnvError>— the code only unwrapped one layerFix
ink::storage::traits::StorageLayouttoContractType'scfg_attrderives.build_createinstantiation with a deterministic address computation (deployer + salt + counter), recording the deployment in storage and emitting the event. On-chain instantiation viabuild_createrequires a concrete contract reference type known at compile time, which is incompatible with a generic factory pattern.Affected file
contracts/factory/src/lib.rs