Problem: The WASM file was being rejected with error:
reference-types not enabled: zero byte expected (at offset 0xba3)
Solution: Added -C target-feature=-reference-types to .cargo/config.toml to disable reference-types during compilation.
File Changed: .cargo/config.toml
[target.wasm32-unknown-unknown]
rustflags = ["-C", "link-arg=-s", "-C", "target-feature=-reference-types"]Problem: The workspace-optimizer was failing with:
missing field `workspace`
Solution:
- Switched to using
cosmwasm/optimizer:0.14.0(single contract optimizer) instead ofcosmwasm/workspace-optimizer:0.14.0 - Added fallback to use
wasm-optlocally if Docker is not available - Updated Makefile to use the single contract optimizer
Files Changed:
Makefile: Updated optimize target to usecosmwasm/optimizer:0.14.0scripts/deploy.sh: Added fallback logic for optimization
The contract now builds with reference-types disabled. To verify:
# Clean and rebuild
cargo clean
cargo build --release --target wasm32-unknown-unknown
# The WASM file should now work on the chainRun the deployment script:
./scripts/deploy.sh testnet mycontractadmin addr_safro1x25weznnzd5k6jv663sdldehqwcjatc44gvrvq 100 addr_safro1x25weznnzd5k6jv663sdldehqwcjatc44gvrvqThe script will:
- Always rebuild to ensure reference-types are disabled
- Try to optimize with Docker (cosmwasm/optimizer)
- Fall back to wasm-opt if Docker fails
- Use unoptimized WASM if both fail (but with reference-types disabled)