1+ #! /bin/bash
2+
3+ # P2P Exchange Program Deployment Script - Solana CLI Only
4+ # This script deploys the program using only Solana CLI tools (no Anchor required)
5+
6+ set -e
7+
8+ echo " 🚀 Starting P2P Exchange Program Deployment to Devnet (Solana CLI Only)"
9+ echo " ========================================================================"
10+
11+ # Colors for output
12+ RED=' \033[0;31m'
13+ GREEN=' \033[0;32m'
14+ YELLOW=' \033[1;33m'
15+ NC=' \033[0m' # No Color
16+
17+ # Configuration
18+ PROGRAM_ID=" 4eLxPSpK6Qi1AyNx79Ns4DoVqodp85sEphzPtFqLKTRk"
19+ NETWORK=" devnet"
20+ KEYPAIR_PATH=" ./program-keypair.json"
21+ PROGRAM_SO_PATH=" ./target/deploy/p2p_exchange.so"
22+
23+ echo " 📊 Deployment Configuration:"
24+ echo " Program ID: $PROGRAM_ID "
25+ echo " Network: $NETWORK "
26+ echo " Keypair: $KEYPAIR_PATH "
27+ echo " Program Binary: $PROGRAM_SO_PATH "
28+
29+ # Check if required tools are installed
30+ echo " 📋 Checking prerequisites..."
31+
32+ if ! command -v solana & > /dev/null; then
33+ echo -e " ${RED} ❌ Solana CLI is not installed${NC} "
34+ echo " Please install from: https://docs.solana.com/cli/install-solana-cli-tools"
35+ exit 1
36+ fi
37+
38+ if ! command -v cargo-build-sbf & > /dev/null; then
39+ echo -e " ${RED} ❌ Solana BPF build tools not found${NC} "
40+ echo " Install Solana CLI which includes cargo-build-sbf"
41+ exit 1
42+ fi
43+
44+ echo -e " ${GREEN} ✅ Prerequisites met${NC} "
45+
46+ # Set Solana CLI to devnet
47+ echo " 🌐 Configuring Solana CLI for devnet..."
48+ solana config set --url https://api.devnet.solana.com
49+ solana config set --keypair ~ /.config/solana/id.json
50+
51+ # Check wallet balance
52+ echo " 💰 Checking wallet balance..."
53+ BALANCE=$( solana balance --lamports)
54+ MIN_BALANCE=2000000000 # 2 SOL in lamports (deployment costs ~1.5 SOL)
55+
56+ if [ " $BALANCE " -lt " $MIN_BALANCE " ]; then
57+ echo -e " ${YELLOW} ⚠️ Low balance detected. Requesting devnet SOL...${NC} "
58+ solana airdrop 2
59+ echo " Waiting for airdrop confirmation..."
60+ sleep 10
61+
62+ # Check balance again
63+ BALANCE=$( solana balance --lamports)
64+ if [ " $BALANCE " -lt " $MIN_BALANCE " ]; then
65+ echo -e " ${RED} ❌ Insufficient balance for deployment${NC} "
66+ echo " Current balance: $( solana balance) SOL"
67+ echo " Required: 2 SOL minimum"
68+ exit 1
69+ fi
70+ fi
71+
72+ echo " Current balance: $( solana balance) SOL"
73+
74+ # Ensure program keypair exists and matches expected ID
75+ if [ ! -f " $KEYPAIR_PATH " ]; then
76+ echo -e " ${YELLOW} ⚠️ Program keypair not found. Generating new one...${NC} "
77+ solana-keygen new --no-bip39-passphrase --force --outfile " $KEYPAIR_PATH "
78+ fi
79+
80+ ACTUAL_PROGRAM_ID=$( solana-keygen pubkey " $KEYPAIR_PATH " )
81+ if [ " $ACTUAL_PROGRAM_ID " != " $PROGRAM_ID " ]; then
82+ echo -e " ${RED} ❌ Program keypair mismatch!${NC} "
83+ echo " Expected: $PROGRAM_ID "
84+ echo " Actual: $ACTUAL_PROGRAM_ID "
85+ echo " Generating correct keypair for expected program ID..."
86+
87+ # For deployment, we'll use the actual keypair and update configs
88+ PROGRAM_ID=" $ACTUAL_PROGRAM_ID "
89+ echo " Updated Program ID: $PROGRAM_ID "
90+ fi
91+
92+ echo -e " ${GREEN} ✅ Program keypair validated${NC} "
93+
94+ # Build the program using Solana CLI tools only
95+ echo " 🔨 Building program with Solana CLI tools..."
96+ cd programs/p2p-exchange
97+
98+ # Clean any existing build artifacts
99+ rm -rf target/
100+
101+ # Build using cargo-build-sbf (Solana CLI tool)
102+ cargo-build-sbf
103+
104+ if [ $? -ne 0 ]; then
105+ echo -e " ${RED} ❌ Build failed${NC} "
106+ exit 1
107+ fi
108+
109+ cd ../..
110+
111+ echo -e " ${GREEN} ✅ Build successful${NC} "
112+
113+ # Verify the binary exists
114+ if [ ! -f " $PROGRAM_SO_PATH " ]; then
115+ echo -e " ${RED} ❌ Program binary not found at $PROGRAM_SO_PATH ${NC} "
116+ exit 1
117+ fi
118+
119+ echo " 📦 Program binary size: $( du -h $PROGRAM_SO_PATH | cut -f1) "
120+
121+ # Deploy the program using Solana CLI
122+ echo " 🚀 Deploying program to devnet..."
123+ echo " This may take a few minutes..."
124+
125+ solana program deploy \
126+ --keypair " $KEYPAIR_PATH " \
127+ --url https://api.devnet.solana.com \
128+ " $PROGRAM_SO_PATH "
129+
130+ if [ $? -ne 0 ]; then
131+ echo -e " ${RED} ❌ Deployment failed${NC} "
132+ exit 1
133+ fi
134+
135+ echo -e " ${GREEN} ✅ Program deployed successfully!${NC} "
136+
137+ # Verify deployment
138+ echo " 🔍 Verifying deployment..."
139+ solana program show " $PROGRAM_ID " --url https://api.devnet.solana.com
140+
141+ if [ $? -eq 0 ]; then
142+ echo -e " ${GREEN} ✅ Deployment verified${NC} "
143+ else
144+ echo -e " ${YELLOW} ⚠️ Could not verify deployment (this is sometimes normal)${NC} "
145+ fi
146+
147+ # Update configuration files with actual program ID
148+ echo " 📝 Updating configuration files..."
149+
150+ # Update lib.rs
151+ sed -i " s/declare_id!(\" .*\" )/declare_id!(\" $PROGRAM_ID \" )/" programs/p2p-exchange/src/lib.rs
152+
153+ # Update Anchor.toml
154+ sed -i " s/p2p_exchange = \" .*\" /p2p_exchange = \" $PROGRAM_ID \" /" Anchor.toml
155+
156+ # Update frontend useProgram.js
157+ if [ -f " src/hooks/useProgram.js" ]; then
158+ sed -i " s/const PROGRAM_ID = new PublicKey(\" .*\" )/const PROGRAM_ID = new PublicKey(\" $PROGRAM_ID \" )/" src/hooks/useProgram.js
159+ fi
160+
161+ # Update frontend App.js network config
162+ if [ -f " src/App.js" ]; then
163+ sed -i " s/programId: \" .*\" /programId: \" $PROGRAM_ID \" /" src/App.js
164+ fi
165+
166+ echo -e " ${GREEN} ✅ Configuration files updated${NC} "
167+
168+ echo " "
169+ echo " 🎉 Deployment Complete!"
170+ echo " =============================="
171+ echo " Program ID: $PROGRAM_ID "
172+ echo " Network: Solana Devnet"
173+ echo " Explorer: https://explorer.solana.com/address/$PROGRAM_ID ?cluster=devnet"
174+ echo " "
175+ echo " 📋 Next Steps:"
176+ echo " 1. Test program functions using the frontend"
177+ echo " 2. Monitor transactions on Solana Explorer"
178+ echo " 3. Initialize admin account using the frontend"
179+ echo " "
180+ echo " 🔗 Useful Commands:"
181+ echo " View program info: solana program show $PROGRAM_ID --url https://api.devnet.solana.com"
182+ echo " Program logs: solana logs $PROGRAM_ID --url https://api.devnet.solana.com"
183+ echo " Account info: solana account $PROGRAM_ID --url https://api.devnet.solana.com"
0 commit comments