forked from ritik4ever/stellar-goal-vault
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
117 lines (97 loc) · 3.5 KB
/
Copy pathdeploy.sh
File metadata and controls
117 lines (97 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/bash
# Deploy Stellar Goal Vault contract to Stellar testnet
#
# Required environment variables:
# SECRET_KEY - Stellar account secret key for deployment
#
# Optional environment variables:
# NETWORK_PASSPHRASE - Network passphrase (defaults to testnet)
# RPC_URL - RPC endpoint URL (defaults to testnet)
#
# Usage:
# SECRET_KEY="S..." ./scripts/deploy.sh
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Configuration
CONTRACTS_DIR="contracts"
CONTRACT_ID_FILE="contract_id.txt"
NETWORK_PASSPHRASE="${NETWORK_PASSPHRASE:-Test SDF Network ; September 2015}"
RPC_URL="${RPC_URL:-https://soroban-testnet.stellar.org:443}"
# Check for required environment variables
if [ -z "$SECRET_KEY" ]; then
echo -e "${RED}Error: SECRET_KEY environment variable is required${NC}"
echo "Please set SECRET_KEY to your Stellar account secret key"
echo "Example: SECRET_KEY=\"S...\" ./scripts/deploy.sh"
exit 1
fi
# Check if soroban-cli is installed
if ! command -v soroban &> /dev/null; then
echo -e "${RED}Error: soroban-cli is not installed${NC}"
echo "Please install it from: https://soroban.stellar.org/docs/getting-started/setup#install-the-soroban-cli"
exit 1
fi
echo -e "${GREEN}Starting contract deployment...${NC}"
echo "Network: Testnet"
echo "RPC URL: $RPC_URL"
echo ""
# Change to contracts directory
cd "$CONTRACTS_DIR" || exit 1
# Build the contract
echo -e "${YELLOW}Building contract...${NC}"
soroban contract build
if [ $? -ne 0 ]; then
echo -e "${RED}Error: Contract build failed${NC}"
exit 1
fi
echo -e "${GREEN}Contract built successfully${NC}"
echo ""
# Deploy the contract
echo -e "${YELLOW}Deploying contract to testnet...${NC}"
# Capture both stdout and stderr, but check exit code separately
DEPLOY_OUTPUT=$(soroban contract deploy \
--wasm target/wasm32v1-none/release/stellar_goal_vault.wasm \
--source-account "$SECRET_KEY" \
--network testnet \
--network-passphrase "$NETWORK_PASSPHRASE" \
--rpc-url "$RPC_URL" \
2>&1)
DEPLOY_EXIT_CODE=$?
if [ $DEPLOY_EXIT_CODE -ne 0 ]; then
echo -e "${RED}Error: Contract deployment failed${NC}"
echo "$DEPLOY_OUTPUT"
exit 1
fi
# Extract contract ID (soroban-cli outputs it directly, may have whitespace)
CONTRACT_ID=$(echo "$DEPLOY_OUTPUT" | grep -oE '[A-Z0-9]{56}' | head -n 1)
# If no 56-char match found, try trimming whitespace from the output
if [ -z "$CONTRACT_ID" ]; then
CONTRACT_ID=$(echo "$DEPLOY_OUTPUT" | tr -d '[:space:]')
fi
# Validate contract ID format (Stellar contract IDs are 56 characters)
if [ ${#CONTRACT_ID} -ne 56 ]; then
echo -e "${RED}Error: Invalid contract ID format${NC}"
echo "Expected 56 characters, got: ${#CONTRACT_ID}"
echo "Output was: $DEPLOY_OUTPUT"
exit 1
fi
# Save contract ID to file
echo "$CONTRACT_ID" > "$CONTRACT_ID_FILE"
# Return to root directory
cd ..
echo ""
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN}Contract deployed successfully!${NC}"
echo -e "${GREEN}========================================${NC}"
echo ""
echo -e "Contract ID: ${YELLOW}$CONTRACT_ID${NC}"
echo -e "Saved to: ${YELLOW}$CONTRACTS_DIR/$CONTRACT_ID_FILE${NC}"
echo ""
echo -e "${GREEN}Next steps:${NC}"
echo "1. Set CONTRACT_ID=$CONTRACT_ID in your backend .env file"
echo "2. Ensure SERVER_PRIVATE_KEY is set in your backend .env file"
echo "3. Restart your backend service"
echo ""