This guide covers deploying the Real Estate DeFi Platform smart contracts to Stellar networks using Stellar CLI.
- Stellar CLI installed
- Rust toolchain with WASM target
- Stellar account with sufficient XLM
- Network access (testnet or mainnet)
The platform includes two main contracts:
- File:
apps/contracts/src/real_estate_token.rs - Purpose: Property tokenization and share management
- Key Features:
- Property tokenization
- Share ownership tracking
- Transfer controls
- Metadata management
- File:
apps/contracts/src/defi_lending.rs - Purpose: Lending pools and borrowing operations
- Key Features:
- Pool creation and management
- Deposit operations
- Collateralized borrowing
- Interest calculation
rustup target add wasm32-unknown-unknowncd apps/contracts
# Build release version
cargo build --target wasm32-unknown-unknown --release
# Output will be in target/wasm32-unknown-unknown/release/# Check if WASM files were created
ls -la target/wasm32-unknown-unknown/release/
# You should see files like:
# real_estate_defi_contracts.wasm# Configure Stellar CLI for testnet
stellar network testnet
# Create or import testnet account
stellar keys generate --network testnet
# Get friendbot funding (testnet only)
stellar account fund $(stellar keys address) --network testnet# Configure Stellar CLI for mainnet
stellar network mainnet
# Import your mainnet account
stellar keys import --name mainnet-account
# Ensure sufficient balance for deployment (usually ~10 XLM)Use the provided deployment script:
# Deploy to testnet
./scripts/deploy.sh testnet
# Deploy to mainnet
./scripts/deploy.sh mainnet
# Deploy specific contract
./scripts/deploy.sh testnet real-estate-token
./scripts/deploy.sh testnet defi-lendingcd apps/contracts
# Deploy contract
CONTRACT_ID=$(stellar contract deploy \
--wasm target/wasm32-unknown-unknown/release/real_estate_defi_contracts.wasm \
--source-account $(stellar keys address) \
--network testnet)
echo "Real Estate Token Contract ID: $CONTRACT_ID"
# Initialize contract
stellar contract invoke \
--contract-id $CONTRACT_ID \
--source-account $(stellar keys address) \
--network testnet \
--function initialize \
--arg "$(stellar keys address)"# Deploy contract (same WASM file, different initialization)
LENDING_CONTRACT_ID=$(stellar contract deploy \
--wasm target/wasm32-unknown-unknown/release/real_estate_defi_contracts.wasm \
--source-account $(stellar keys address) \
--network testnet)
echo "DeFi Lending Contract ID: $LENDING_CONTRACT_ID"
# Initialize lending contract
stellar contract invoke \
--contract-id $LENDING_CONTRACT_ID \
--source-account $(stellar keys address) \
--network testnet \
--function initialize \
--arg "$(stellar keys address)"Update your environment files with contract IDs:
# .env.local
REAL_ESTATE_TOKEN_CONTRACT_ID=your_contract_id_here
DEFI_LENDING_CONTRACT_ID=your_lending_contract_id_here
STELLAR_NETWORK=testnetUpdate frontend configuration:
// apps/webapp/src/config/contracts.ts
export const CONTRACTS = {
REAL_ESTATE_TOKEN: process.env.NEXT_PUBLIC_REAL_ESTATE_TOKEN_CONTRACT_ID,
DEFI_LENDING: process.env.NEXT_PUBLIC_DEFI_LENDING_CONTRACT_ID,
};Update API configuration:
// apps/api/src/config/contracts.ts
export const CONTRACTS = {
REAL_ESTATE_TOKEN: process.env.REAL_ESTATE_TOKEN_CONTRACT_ID,
DEFI_LENDING: process.env.DEFI_LENDING_CONTRACT_ID,
};# Verify contract is deployed
stellar contract read \
--contract-id $CONTRACT_ID \
--network testnet \
--function admin# Test property tokenization
stellar contract invoke \
--contract-id $CONTRACT_ID \
--source-account $(stellar keys address) \
--network testnet \
--function get_property_info \
--arg "TEST_PROPERTY_ID"# Test API integration
curl http://localhost:3001/api/properties/TEST_PROPERTY_IDcd apps/contracts
# Make changes to contracts
# Build new version
cargo build --target wasm32-unknown-unknown --release# Deploy new version
stellar contract deploy \
--wasm target/wasm32-unknown-unknown/release/real_estate_defi_contracts.wasm \
--source-account $(stellar keys address) \
--network testnetSome upgrades may require data migration:
# Call migration functions
stellar contract invoke \
--contract-id $CONTRACT_ID \
--source-account $(stellar keys address) \
--network testnet \
--function migrate_data# Monitor contract events
stellar contract events \
--contract-id $CONTRACT_ID \
--network testnet \
--followTrack these metrics:
- Transaction success rate
- Gas usage per operation
- Response times
- Error rates
- Watch for unusual activity
- Monitor admin function calls
- Track large token transfers
- Verify contract state consistency
# Check account balance
stellar balance
# Fund testnet account
stellar account fund $(stellar keys address) --network testnet# Verify contract ID format
stellar contract info $CONTRACT_ID --network testnet# Get transaction details
stellar transaction --id $TRANSACTION_ID --network testnet- "Insufficient fee": Increase transaction fee
- "Contract not found": Verify contract ID and network
- "Authorization failed": Check signing account
- "Invalid argument": Verify function parameters
- Test thoroughly on testnet before mainnet deployment
- Use environment variables for contract IDs
- Implement proper error handling in frontend integration
- Monitor contract usage and performance
- Keep backup of deployment scripts and configurations
- Document any custom contract modifications
- Use multisig for admin functions in production
- Implement access controls for sensitive operations
- Regular audits of contract code
- Monitor for suspicious activity
- Keep admin keys secure and use hardware wallets
This deployment process ensures your smart contracts are properly deployed and integrated with the entire Real Estate DeFi Platform.