2025-06-22 07:31:51 +03:00

143 lines
3.5 KiB
Bash
Executable File

#!/bin/bash
# ๐Ÿš€ FIXED ONE SCRIPT TO DEPLOY EVERYTHING
set -e
echo "๐ŸŒŸ Deploying Stellar Price Oracle - Fixed Version"
# Install Stellar CLI
echo "๐Ÿ“ฆ Installing Stellar CLI..."
cargo install --locked stellar-cli --features opt --force
# Add WASM target
rustup target add wasm32-unknown-unknown
# Setup testnet
echo "๐ŸŒ Setting up testnet..."
stellar network add --global testnet \
--rpc-url https://soroban-testnet.stellar.org:443 \
--network-passphrase "Test SDF Network ; September 2015"
# Create account
echo "๐Ÿ”‘ Creating deployment account..."
stellar keys generate deployer --network testnet --global
# Fund account with proper network passphrase
echo "๐Ÿ’ฐ Funding account..."
stellar keys fund deployer \
--network testnet \
--network-passphrase "Test SDF Network ; September 2015"
# Check balance
echo "๐Ÿ’ณ Checking balance..."
stellar account --id $(stellar keys address deployer) --network testnet
# Build contract
echo "๐Ÿ—๏ธ Building smart contract..."
cd contract
cargo build --target wasm32-unknown-unknown --release
cd ..
# Deploy contract with alias
echo "๐Ÿš€ Deploying contract to Stellar..."
stellar contract deploy \
--wasm contract/target/wasm32-unknown-unknown/release/stellar_price_oracle.wasm \
--source deployer \
--network testnet \
--alias price_oracle
CONTRACT_ID=$(stellar contract id --alias price_oracle --network testnet)
echo "โœ… Contract deployed: $CONTRACT_ID"
# Create .env with everything
echo "โš™๏ธ Creating .env..."
cat > .env << EOF
STELLAR_RPC_URL=https://soroban-testnet.stellar.org:443
STELLAR_NETWORK=testnet
PROVIDER_SECRET=$(stellar keys show deployer)
ORACLE_CONTRACT_ID=$CONTRACT_ID
API_PORT=3001
UPDATE_INTERVAL=30000
VITE_API_URL=http://localhost:3001
VITE_STELLAR_RPC=https://soroban-testnet.stellar.org:443
VITE_CONTRACT_ID=$CONTRACT_ID
EOF
# Install backend dependencies
echo "๐Ÿ“ฆ Installing backend..."
cd oracle-service
npm install
cd ..
# Install frontend dependencies
echo "๐ŸŽจ Installing frontend..."
cd frontend
npm install
cd ..
# Start backend
echo "๐ŸŒ Starting backend..."
cd oracle-service
npm start &
BACKEND_PID=$!
cd ..
# Wait for backend
sleep 5
# Test backend
echo "๐Ÿงช Testing backend..."
curl -s http://localhost:3001/health || echo "Backend starting..."
# Start frontend
echo "๐ŸŽจ Starting frontend..."
cd frontend
npm run dev &
FRONTEND_PID=$!
cd ..
# Wait for frontend
sleep 5
# Example test call (set price)
echo "๐Ÿงช Testing contract..."
stellar contract invoke \
--id price_oracle \
--source deployer \
--network testnet \
-- \
set_price \
--pair BTC \
--price 123456 \
--provider $(stellar keys address deployer)
# Example test call (get price)
stellar contract invoke \
--id price_oracle \
--source deployer \
--network testnet \
-- \
get_price \
--pair BTC
echo ""
echo "๐ŸŽ‰ EVERYTHING IS RUNNING!"
echo "========================"
echo ""
echo "๐Ÿ“‹ Contract ID: $CONTRACT_ID"
echo "๐Ÿ” Explorer: https://stellar.expert/explorer/testnet/contract/$CONTRACT_ID"
echo "๐ŸŒ Frontend: http://localhost:5173"
echo "๐Ÿ“Š Backend: http://localhost:3001/health"
echo ""
echo "๐Ÿ›‘ To stop: kill $BACKEND_PID $FRONTEND_PID"
echo ""
echo "๐Ÿ† Your oracle is live with real smart contracts!"
# Save PIDs for easy stopping
echo "BACKEND_PID=$BACKEND_PID" > .pids
echo "FRONTEND_PID=$FRONTEND_PID" >> .pids
echo ""
echo "๐Ÿ’ก Quick commands:"
echo " Test contract: stellar contract invoke --id $CONTRACT_ID --source deployer --network testnet -- get_assets"
echo " Stop services: kill $BACKEND_PID $FRONTEND_PID"
echo " View logs: tail -f oracle-service/*.log"