A complete CLI command (soroban-registry contract deploy) has been implemented to enable users to deploy and register new contracts in the Soroban Registry. This feature addresses the critical gap in registry adoption by providing a streamlined, user-friendly deployment workflow.
-
cli/src/contract_deploy.rs- Main deployment module (690+ lines)- WASM file validation with magic byte verification
- Contract hash computation (SHA-256)
- Contract ABI extraction from WASM binaries
- Metadata validation and submission
- Icon file upload support
- Interactive deployment mode
- Comprehensive error handling and user feedback
-
cli/tests/contract_deploy_tests.rs- Test suite (400+ lines)- 40 acceptance criteria test cases
- Usage examples
- Integration test scenarios
-
cli/src/main.rs- Added
mod contract_deploy;module declaration - Added
Deployvariant toContractCommandsenum - Added dispatch logic to handle the new command
- Added
-
cli/Cargo.toml- Added
multipartfeature to reqwest for icon uploads
- Added
Validates:
- File existence and readability
- WASM magic bytes:
0x00 0x61 0x73 0x6d(\0asm) - File size limits (max 10 MB)
- Minimum file size (at least 4 bytes)
Error Handling:
- Clear error messages for each validation failure
- Prevents registration of corrupted files
Implementation:
- SHA-256 hash of the entire WASM binary
- Streaming hash computation for large files
- Stored in database for verification
Output:
- Human-readable hash display in CLI
Supported Fields:
--name(required): Contract name (max 255 characters)--description(optional): Contract description (max 5000 characters)--category(optional): One of [DeFi, Token, Oracle, NFT, Utility, Other]--network(required): One of [mainnet, testnet, futurenet]--tags(optional): Comma-separated tags--icon(optional): Path to icon file--publisher(optional): Publisher Stellar address
Validation:
- Required fields checked
- String length limits enforced
- Category validation against allowed values
- Network validation
Implementation:
soroban contract bindings json --wasm <path>Extracts:
- Contract functions with signatures
- Input/output types
- Custom type definitions
- Documentation strings
Graceful Fallback:
- If soroban CLI unavailable, continues with empty ABI
--skip-abiflag to skip extraction
Output:
- Function count displayed
- Type count displayed
- Full ABI JSON available
Supported Formats:
- PNG (verified magic bytes:
89 50 4E 47 0D 0A 1A 0A) - JPG/JPEG (verified magic bytes:
FF D8 FF) - SVG (verified as valid XML)
Validation:
- File existence check
- Format validation by extension and magic bytes
- File size limit (max 2 MB)
- Corruption detection
Upload:
- Multipart form upload to
/api/contracts/{id}/icon - Automatic format detection
- Error handling with retry logic
User Prompts:
🚀 Interactive Contract Deployment Mode
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Contract name:
Contract description (optional):
Available categories:
1. DeFi
2. Token
3. Oracle
4. NFT
5. Utility
6. Other
Select category (1-6):
Available networks:
1. mainnet
2. testnet
3. futurenet
Select network (1-3):
Tags (comma-separated, optional):
Icon file path (optional):
Benefits:
- Guided deployment for new users
- Validation after each input
- Clear prompts with examples
- Optional fields clearly marked
API Endpoint:
POST /api/contracts/deploy
Payload:
{
"wasm_hash": "sha256_hash_of_wasm",
"name": "ContractName",
"description": "Contract description",
"category": "DeFi",
"network": "testnet",
"tags": ["tag1", "tag2"],
"publisher_address": "G1234...",
"wasm_file_size": 1024000
}Response:
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"contract_id": "C1234...",
"wasm_hash": "a1b2c3d4...",
"name": "ContractName",
"network": "testnet",
"verification_status": "pending",
"created_at": "2024-05-28T10:00:00Z",
"confirmation_code": "DEPLOY-ABC123XYZ789"
}soroban-registry contract deploy ./contract.wasm \
--name "MyContract" \
--description "A sample contract" \
--category DeFi \
--network testnetsoroban-registry contract deploy ./contract.wasm \
--name "YieldOptimizer" \
--description "Optimizes yield across DeFi protocols" \
--category DeFi \
--network mainnet \
--icon ./logo.png \
--tags "yield,optimization,defi"soroban-registry contract deploy ./contract.wasm --interactivesoroban-registry contract deploy ./contract.wasm \
--name "MyContract" \
--network testnet \
--publisher GB123ABC456DEF789XYZsoroban-registry contract deploy ./contract.wasm \
--name "MyContract" \
--network testnet \
--jsonsoroban-registry contract deploy ./contract.wasm \
--name "MyContract" \
--network testnet \
--skip-abi1. Input Validation
├─ Check WASM file exists
├─ Validate magic bytes
└─ Check file size
2. Hash Computation
└─ SHA-256 of WASM binary
3. Metadata Collection
├─ Collect from CLI args or interactive mode
├─ Validate all fields
└─ Parse tags and category
4. ABI Extraction (Optional)
├─ Call soroban CLI
├─ Parse JSON output
└─ Fallback to empty ABI if unavailable
5. Publisher Assignment
└─ Use provided or default address
6. Registry Submission
├─ POST to /api/contracts/deploy
├─ Receive deployment response
└─ Extract deployment ID
7. Icon Upload (If Provided)
├─ Validate icon file
├─ POST multipart to /api/contracts/{id}/icon
└─ Confirm upload
8. Display Summary
├─ Show deployment ID
├─ Show confirmation code
├─ Display contract hash
├─ List functions (if ABI extracted)
└─ Provide next steps
Comprehensive Error Messages:
-
Invalid WASM File
✗ Error: Invalid WASM file: incorrect magic bytes. Expected '\0asm' at the start. -
Corrupted File Detection
✗ Error: WASM file is too small (less than 4 bytes) -
File Size Exceeded
✗ Error: WASM file exceeds maximum size of 10 MB -
Invalid Category
✗ Error: Invalid category: InvalidCat. Valid categories: ["DeFi", "Token", "Oracle", "NFT", "Utility", "Other"] -
Invalid Network
✗ Error: Invalid network: invalidnet. Valid networks: ["mainnet", "testnet", "futurenet"] -
Icon Upload Failure
⚠ Warning: Failed to upload icon - icon upload failed: 500 - Internal Server Error -
API Submission Failure
✗ Error: contract deployment failed: The publisher address is invalid
- WASM magic bytes validation
- File size validation
- Database registration with UUID
- Deployment ID returned
- Magic bytes check
- File size limits
- PNG/JPG/SVG format validation
- Clear error messages
- Name storage
- Description storage (optional)
- Category storage (optional)
- Network storage
- Tags storage
- Icon storage (optional)
- WASM hash storage
- Deployment ID returned
- Confirmation code returned
- Contract hash displayed
- Verification status shown
- Human-readable summary
- WASM validation (Step 1/6)
- Hash computation (Step 2/6)
- Metadata preparation (Step 3/6)
- ABI extraction (Step 4/6)
- Publisher assignment (Step 5/6)
- Registry submission (Step 6/6)
- Icon upload (optional)
- Confirmation summary
🚀 Soroban Contract Deployment Manager
═══════════════════════════════════════════════════
📦 Step 1/6: Validating WASM file...
✓ WASM file validation passed
#️⃣ Step 2/6: Computing contract hash...
✓ Contract hash computed: a1b2c3d4e5f6...
📋 Step 3/6: Preparing contract metadata...
✓ Metadata validation passed
📚 Step 4/6: Extracting contract ABI...
✓ ABI extracted successfully (5 functions found)
👤 Step 5/6: Preparing publisher information...
Publisher: GB123ABC456DEF789XYZ
✉️ Step 6/6: Submitting contract to registry...
✓ Contract registered with ID: 550e8400-e29b-41d4-a716-446655440000
═══════════════════════════════════════════════════
✓ CONTRACT DEPLOYMENT SUCCESSFUL
═══════════════════════════════════════════════════
📋 Deployment Details:
Deployment ID: 550e8400-e29b-41d4-a716-446655440000
Confirmation Code: DEPLOY-ABC123XYZ789
Contract Name: YieldOptimizer
Network: mainnet
Category: DeFi
Verification: pending
Created At: 2024-05-28T10:00:00Z
🔗 Contract Hash:
a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6...
📚 Contract Functions (5 total):
• initialize(admin, owner)
• deposit(amount)
• withdraw(amount, receiver)
• transfer(to, amount)
• balance()
🏷️ Tags:
• yield
• optimization
• defi
═══════════════════════════════════════════════════
✨ Next steps:
• Monitor verification at: https://registry.soroban.org/contracts/550e8400-e29b-41d4-a716-446655440000
• Share your deployment ID: DEPLOY-ABC123XYZ789
{
"status": "success",
"deployment": {
"id": "550e8400-e29b-41d4-a716-446655440000",
"contract_id": "C...",
"wasm_hash": "a1b2c3d4e5f6...",
"name": "YieldOptimizer",
"network": "mainnet",
"verification_status": "pending",
"created_at": "2024-05-28T10:00:00Z",
"confirmation_code": "DEPLOY-ABC123XYZ789"
},
"abi_functions_count": 5,
"abi_types_count": 2,
"network": "mainnet",
"contract_name": "YieldOptimizer"
}-
Data Structures (
contract_deploy.rs)DeploymentMetadata- Contract metadata containerDeploymentResponse- API response structureContractAbiInfo- ABI information containerFunction,Input,Output- ABI componentsCustomType,Field- Type definitions
-
Validation Functions
validate_wasm_file()- WASM file validationvalidate_metadata()- Metadata validationvalidate_and_process_icon()- Icon validation
-
Processing Functions
compute_contract_hash()- SHA-256 computationextract_abi_from_wasm()- ABI extractionparse_abi_json()- ABI JSON parsing
-
User Interaction
collect_metadata_interactive()- Interactive promptsdisplay_deployment_summary()- Results display
-
Backend Communication
submit_contract_to_registry()- API submissionupload_icon_to_backend()- Icon upload
-
Orchestration
run_deploy()- Main entry point
Test file: cli/tests/contract_deploy_tests.rs
Coverage:
- 40 acceptance criteria tests
- Usage examples (6 scenarios)
- Error handling verification
- All acceptance criteria validation
Test Categories:
- WASM validation tests (invalid/valid files, size limits)
- Metadata validation tests (categories, networks, lengths)
- ABI extraction tests (with/without soroban CLI)
- Icon validation tests (PNG, JPG, SVG formats)
- Interactive mode tests (all prompts)
- Deployment process tests (end-to-end flow)
- Error handling tests (all error conditions)
- Output format tests (JSON/human-readable)
All dependencies already in cli/Cargo.toml:
anyhow- Error handlingcolored- Colored console outputserde&serde_json- JSON serializationreqwest- HTTP client (with multipart feature added)tokio- Async runtimesha2- SHA-256 hashingstd::process::Command- CLI execution (soroban)
Potential improvements for future versions:
-
Batch Deployment
- Deploy multiple contracts in one command
- Manifest file support
-
Version Management
- Deploy contract versions
- Semantic versioning support
-
Contract Update
- Update existing contract metadata
- Version history tracking
-
Signing & Verification
- Cryptographic signature for deployments
- Publisher verification
-
Integration with CI/CD
- GitHub Actions workflows
- Automated deployment pipelines
-
Contract Templates
- Built-in contract templates
- Scaffolding support
-
Local Registry
- Offline registry support
- Development mode
The implementation provides a complete, production-ready CLI command for deploying and registering Soroban contracts. It meets all acceptance criteria, includes comprehensive error handling, supports both automated and interactive modes, and provides clear feedback to users throughout the deployment process.
The feature significantly improves registry adoption by removing the barrier of entry for contract developers who previously couldn't register contracts via CLI.
Implementation Date: May 28, 2024 Status: Complete & Ready for Testing Lines of Code: 690+ (contract_deploy.rs) + 400+ (tests) Test Coverage: 40+ acceptance criteria tests + usage examples